complete blank
Member
- Joined
- May 5, 2017
- Messages
- 71
- Solutions
- 5
- Reaction score
- 15
If you write scripts offline and have files in the same directory as the one you are working and would like to get the current directory or load another file in the current directory you can use this function to that since dofile requires an absolute path.
If file is omitted then it just returns the current directory. I have not had a chance to test it on windows but passing it a string like structure of a windows path did yield the expected outcome.
LUA:
function cwd(file)
local chr = os.tmpname():sub(1,1)
if chr == "/" then
-- linux
chr = "/[^/]*$"
else
-- windows
chr = "\\[^\\]*$"
end
return arg[0]:sub(1, arg[0]:find(chr))..(file or '')
end
If file is omitted then it just returns the current directory. I have not had a chance to test it on windows but passing it a string like structure of a windows path did yield the expected outcome.