Jump to content

FileOpen() can't open from subfolder?


VioFX
 Share

Recommended Posts

Okay so I've got my program here and want to give it to a few friends, so I can't specify exactly what folder it will be on. So how can I open a file using FileOpen() from a subfolder where the .exe is located?

Here's what I'm using:

If _GUICtrlTreeView_GetSelected($mainTree, $subfolderItem) Then
            $file = FileOpen("\Subfolder\Subfolder.ini", 0)
            Else
            EndIf

Using this as a test to see if it opens from "\Subfolder\" which is where the .exe is located. But whenever this function runs it just closes my program, so I assume it couldn't find the file. Because when I replace it with this:

$file = FileOpen("Subfolder.ini", 0)

and put the "Subfolder.ini" in the same folder as the .exe it runs fine and does everything it's supposed to. I've searched around and haven't really found someone with the same question because every post I find that has to do with this have people who set a specific folder to look in. I'm trying to find it from a subfolder that's located anywhere the .exe is placed.

Probably the simplest issue which I'm going to be very embarrassed with... but I just can't get it.

Edited by VioFX
Link to comment
Share on other sites

Having "\" at the beginning of the string indicates it starts at root, as in C:\Subfolder. If you leave the starting backslash off, then it can be a relative path. So perhaps one of these:

$file = FileOpen("Subfolder\Subfolder.ini", 0)

$file = FileOpen(".\Subfolder\Subfolder.ini", 0)

$file = FileOpen(@Workingdir & "\Subfolder\Subfolder.ini", 0)

:unsure:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Okay so I've got my program here and want to give it to a few friends, so I can't specify exactly what folder it will be on. So how can I open a file using FileOpen() from a subfolder where the .exe is located?

If you by .exe mean your AutoIt script, use @ScriptDir :unsure:
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...