get current working directory in Lua

user600838 picture user600838 · May 17, 2011 · Viewed 34.1k times · Source

What's the Lua to get the current working directory on Windows XP SP3 (or to get the directory of the currently-running Lua file)? I prefer not to use LuaFileSystem.

I can't use os.execute("cd") because os.execute always starts from my home directory (and thus always yields C:\Documents and Settings\username).

Answer

jpjacobs picture jpjacobs · May 17, 2011

maybe some ugly hack like

current_dir=io.popen"cd":read'*l'