Is there a way CMD can open a folder with an emoji in its name by using os.execute in Lua 5.2?

208 views Asked by At

As soon as I try to access a folder/file containing an emoji in its name from my Lua 5.2 script, for example like this:

os.execute('start "" "' .. path .. "\\scripts\\menu\\ My Scripts" .. '"')

The Windows' Command Prompt simply refuses to open it with the following error message:

CMD and emoji in path issue

I'm aware Windows' Command Prompt doesn't support emojis and therefore is not possible to make it work just like that, but my doubt is if won't exist some workaround or whatever I can do to ensure any Windows/Unix user is going to able to get the folder open by my Lua script without any problem.

I have tried i.e. things like use the codes instead (1246 and U+1F4F0 in this page facing up case) without success. Couldn't I for example simply use some kind of "wildcard" instead? I mean, knowing it's always going to be the very first character in the name. Or, well, any other ideas will be welcomed, cause nothing I'm trying really seems to work...

Of course if it's going to represent any problem I'll simply refuse to use them, but it came in handy for some "first sight" folder distinction and, if possible, I'd like to can count this little visual resource

2

There are 2 answers

6
koyaanisqatsi On

This is a Problem about how the string is constructed.
I found only one solution with [[command "path"]] (on Windows 11 and Lua 5.3)...

os.execute([[start ]] .. path .. [["\scripts\menu\ My Scripts"]])
-- My Testpath is/was: os.execute([[dir "%localappdata%\nvim\ Lua"]])

...the long string ([[]]) will not be interpreted (coercionated) by Lua.
That also have the side effect that you can use single backslashs with that kind of string.
Environment variable expansion (e.g. Windows: %localappdata%) only works inside doublequotes.
Single quotes instead ([[command '%localappdate%\path\']]) will not work (expanded).

3
Egor Skriptunoff On

os.execute accepts only ANSI-encoded strings (win-1252 in European Windows), but it is unable to encode an emoji.

Hint: you can create .bat-file to do the task for you and invoke it from Lua with os.execute.