get current working directory in Lua

后端 未结 5 1322
北荒
北荒 2021-01-04 01:37

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 LuaFileSyste

5条回答
  •  余生分开走
    2021-01-04 02:36

    I haven't had time to test this, but have you tried os.getenv to read windows environment variables?

    Windows has an environment variable for current directory: %CD%

    os.getenv("CD")
    

    Edit: Tested on Windows 7 and while other environment variables work (ie. %USERNAME% or %PROGRAMFILES%) the CD var returns nil

提交回复
热议问题