Jump to content
The simFlight Network Forums

Current Directory when writing files


Recommended Posts

Posted

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?

Posted

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.

Posted
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

Posted

...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?

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.