Jump to content

Recommended Posts

Posted

 

Just burned the last two hours of my life trying to figure out how relative include statements work in autoit. I wanted to share how I resolved it here in case anyone googles a similar issue in the future. 

Example:

working on test.au3 in the following path:

C:/Users/Bill/autoit/project/test.au3

if I want to import the file "myfile.au3" which is in the project directory (same as test.au3), I can do:

#include "myfile.au3"

or I can use

#include ".\myfile.au3"

as far as I can tell, these two lines are equivalent. the "." means "the directory that this file is currently in", in this case the file is test.au3, which is in the "project" directory.

Now, let's say I want to include "myotherfile.au3" instead, which is in the "autoit" directory. I can do:

#include "..\myotherfile.au3"

the ".." means "one level higher relative to the directory that this file is currently in". 

Finally, let's say I want to include "twohoursofmylifegone.au3", which resides in the "Bill" directory

Intuitively, you might think the following code would work:

#include "...\twohoursofmylifegone.au3"

Especially when the documentation says:

Quote

If "..." is used, the filename is taken to be relative to the current script.

But this would give you an error. The correct syntax is:

#include "..\..\twohoursofmylifegone.au3"

Which kinda makes sense, but only kinda. Apparently this period syntax is a common convention, but if you don't know this... hopefully you were lucky enough to find this page. Any way the docs could be updated to make this more clear?

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