kaha Posted Saturday at 11:11 AM Report Posted Saturday at 11:11 AM I write and read files from lua scripts. I do this basically like this: os.execute("if not exist Aircraft_States (mkdir Aircraft_States)") filename = "Test" io.open("Aircraft_States/"..filename, "w") io.output(file) io.write("Test...\n") io.close(file) The os.execute statement creates subfolder "Aircraft_States" in the FSUIPC7 installation folder. The io.open statement opens file "Test" in subfolder "Aircraft_States", the complete path of the file is "C:\FSUIPC7\Aircraft_States\Test". It seems the line "LuaPath=Lua" in section [LuaFiles] changse the parent folder for the io.open statement to "C:\FSUIPC7\Lua". Is there a possibility to find the current directory where file open statements are done?
John Dowson Posted Monday at 07:41 AM Report Posted Monday at 07:41 AM You cannot access the LuaPath setting. But why do you need this? Can you not just use relative paths, as you seem to be doing?
kaha Posted Monday at 08:22 AM Author Report Posted Monday at 08:22 AM Yes, I use relative paths. But the script is not portable. I made a script I want to publish. It will not work if different path values are used in the .ini file.
John Dowson Posted Monday at 08:30 AM Report Posted Monday at 08:30 AM 3 minutes ago, kaha said: But the script is not portable. It will be portable if you use relatibe paths - thats the whole point. 4 minutes ago, kaha said: It will not work if different path values are used in the .ini file. Why not? If relative paths are used, it doesn't matter what the root of the relative path actually is. I guess could add a lua function to return the LuaPath setting, but this shouldn't be needed. John
John Dowson Posted Monday at 08:39 AM Report Posted Monday at 08:39 AM ...or is it because the io.execute statement is not running under the LuaPath folder, so its creating the directory in the wrong place? I can see that you may need the LuaPath there...is there not an lua io function that can create a folder?
kaha Posted Monday at 08:44 AM Author Report Posted Monday at 08:44 AM I think there's only open, close, read, write and seek. Edit: well, some more, but no create folder function.
kaha Posted Monday at 08:50 AM Author Report Posted Monday at 08:50 AM I could parse the .ini file and look for the LuaPath entry, but I don't know the location of the installation folder.
John Dowson Posted Monday at 09:06 AM Report Posted Monday at 09:06 AM I have added an ipc.getLuaPath() function in the attached version. John FSUIPC7.exe
kaha Posted Monday at 09:24 AM Author Report Posted Monday at 09:24 AM This works. Only one question left: I use a script to parse input events from the .log file. If LuaPath is used I don't know where's the installation folder. If the path is relative I could trace it back, but with an absolute path there's no chance.
John Dowson Posted Monday at 11:17 AM Report Posted Monday at 11:17 AM I have added another function ipc.getInstallationFolder() that returns the installation folder (with trailing '\' included). John FSUIPC7.exe
kaha Posted Monday at 11:32 AM Author Report Posted Monday at 11:32 AM Perfect, this works. Thank you, Karl
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now