Sign in to follow this  
Followers 0
fade2gray

#include - understanding paths

21 posts in this topic

Example from the help file.

;;; TIME.AU3;;;
MsgBox(0,"", "The time is " & @HOUR & ":" & @MIN & ":" & @SEC)

;;; SCRIPT.AU3;;;
#include "TIME.AU3"
MsgBox(0,"", "Example")
#include "TIME.AU3"
Exit

; Running script.au3 will output three message boxes:
; one with the time, one with 'Example', and another with the time.

C:\Program Files\AutoIt\Include\TIME.AU3

C:\My Documents\AutoIt\SCRIPT.AU3

Why does the script run without error whether I use

#include "TIME.AU3"
or
#include <TIME.AU3>

I got the impression from the help file that if I used "...", only the directory the script is running in and the same directory with \include appended would be searched - unless I create a registry key to include other directories, which I haven't.

Also, just to add to the confusion, I didn't use the installer to "install" AutoIt.

For the include library syntax (#include <file>) to work AutoIt must have been installed using the supplied installer otherwise the installation directory will not be known and the current script directory (@ScriptDir\Include) will be used instead.

Maybe the help file is a little out of date?

Share this post


Link to post
Share on other sites



Don't you people read the helpfile?

The search order used by AutoIt depends on which form of #include you use. The tables below show the order directories are searched using both forms.

Using #include <>

Standard library The path of the currently running interpreter with "\Include" appended is searched.

User-defined libraries The registry value mentioned above is read and each directory is searched in the order they appear in.

Script directory The directory of the currently executing script.

Using #include "" (This is the reverse of #include <>).

Script directory The directory of the currently executing script.

User-defined libraries The registry value mentioned above is read and each directory is searched in the reverse order they appear in.

Standard library The path of the currently running interpreter with "\Include" appended is searched.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Don't you people read the helpfile?

Before you start spouting RTFM, perhaps you should have read and understood my post first. Edited by fade2gray

Share this post


Link to post
Share on other sites

I did read your first post. You said:

I got the impression from the help file that if I used "...", only the directory the script is running in and the same directory with \include appended would be searched - unless I create a registry key to include other directories, which I haven't.

Which is wrong, and you would have known that if you had read the helpfile.

Share this post


Link to post
Share on other sites

Ok, perhaps I ought to pay more attention.

I read "interpreter" as "script" in...

Using #include "" (This is the reverse of #include <>).

Script directory The directory of the currently executing script.

User-defined libraries The registry value mentioned above is read and each directory is searched in the reverse order they appear in.

Standard library The path of the currently running interpreter with "\Include" appended is searched.

But that doesn't explain why #include works for me anyway when the help file says it will only work if I used the installer.

Share this post


Link to post
Share on other sites

But that doesn't explain why #include works for me anyway when the help file says it will only work if I used the installer.

You answered your own question there.

Standard library The path of the currently running interpreter with "\Include" appended is searched.

So if you run AutoIt.exe from C:\Program Files\AutoIt\ it will search includes from C:\Program Files\AutoIt\Include\ which is where you had the file, right?

Share this post


Link to post
Share on other sites

Because the installer knows where to put things and if u put things in the right place (as the installer would) it might just work.

The are reasons why #include "TIME.AU3" or #include <TIME.AU3> works when using includes none of which are really important - if it works 4 you, thats great! Rule of thumb which I assume you know, use <> for libraries and "" for your own created files - and try and use the installer, it is there for a reason.

If you really want to learn why, install a C compiler, something old and primitive - play round with the files and you'll learn why things are the way they are.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

You answered your own question there.

So if you run AutoIt.exe from C:\Program Files\AutoIt\ it will search includes from C:\Program Files\AutoIt\Include\ which is where you had the file, right?

But in my case, "C:\Program Files\AutoIt\Include\ " <> "@ScriptDir\Include"

For the include library syntax (#include <file>) to work AutoIt must have been installed using the supplied installer otherwise the installation directory will not be known and the current script directory (@ScriptDir\Include) will be used instead.

So why does "#include <TIME.AU3>" work for me as well as "#include "TIME.AU3""? It seems like the latter quote is mis-information.

Thanks for your patience, I guess I should be grateful that it works in either case.

Share this post


Link to post
Share on other sites

Well since what happens for you is exactly what is described in the table i copied from the helpfile earlier, I think it's safe to ignore that part about using the installer.

I myself use the installer, why don't you? I think it's quite handy to be able to right-click a file and edit/run it, or even create a new file.

Share this post


Link to post
Share on other sites

Is the problem - it does not work or you don't understand why it works?


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

From the HelpFile:

There is a special registry value that can be created at "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt" called "Include". It should be a REG_SZ (string) value. The contents of this value are a semi-colon delimited list of directories that should be searched for files when resolving #include's in addition to the standard locations.

"HKCU\Software\AutoIt v3\AutoIt\Include" = Directories that are searched

#incude "time.au3" (one dblquote at end) searches Script directory only

#include <time.au3> searches Standard library, then User-defined libraries, then Script directory

#incude "time.au3"" (two dblquote at end) searches Script directory, then User-defined libraries, then Standard library, reversed order from <>

there are 3 choices as stated in the help file for "Include"

Edited by Varian

Share this post


Link to post
Share on other sites

quick semi related question. is there any way to use relative paths to include files? I am working on a project with a friend and making sure that we have teh same includes and versions is getting to be a pain.

Share this post


Link to post
Share on other sites

Good lord. You're taking one piece of documentation as gospel and using that to refute everything else. Problem is what you are believing is simply no longer true and I will remove it from the documentation after I finish this post. However, why you continue to believe the piece of documentation is right after having it proved to you that it is not is beyond me.

And just so we're clear here, the paragraph:

For the include library syntax (#include <file>) to work AutoIt must have been installed using the supplied installer otherwise the installation directory will not be known and the current script directory (@ScriptDir\Include) will be used instead.

is WRONG and will be removed.

Share this post


Link to post
Share on other sites

@Varian

You need to reread the helpfile, there is no third choice.

@ghetek

Yes there is. You write them as you would normally write relative paths (#include "..\something.au3"

Share this post


Link to post
Share on other sites

AdmiralAlkex:

You are correct..

"Time.au3" & "Time.au3"" now do the same thing..there is no @Scriptdir search only anymore

Share this post


Link to post
Share on other sites

Would it not be simpler to do the same thing as most other language and as the help file suggests?

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

If <...> is used the filename is taken to be relative to include library directory

Unless your trying to override a library (why anyone would is another story), that will work every time. Keep it simple and it will work :P


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Would it not be simpler to do the same thing as most other language and as the help file suggests?

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

If <...> is used the filename is taken to be relative to include library directory

Unless your trying to override a library (why anyone would is another story), that will work every time. Keep it simple and it will work :P

It is simple.

Share this post


Link to post
Share on other sites

so were clear, i'm not saying its not simple, AutoIt includes are simple.

Keep it simple and it will work every time was the suggestion. Don't mess with what works. :P


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Good lord. You're taking one piece of documentation as gospel and using that to refute everything else. Problem is what you are believing is simply no longer true and I will remove it from the documentation after I finish this post. However, why you continue to believe the piece of documentation is right after having it proved to you that it is not is beyond me.

Some people have become so isolated in their ivory towers that they have forgoten what it is to start from ground level.

It seems increasingly the case lately, that when searching for a solution, the only hits I find are find are in forums where a similar question has been posted, and the only answer - RTFM, search the forum, google or similar.

"However, why you continue to believe the piece of documentation is right after having it proved to you that it is not is beyond me."

You are under some misapprehension. I believe it was me who brought the discrepancy to light.

So why does "#include <TIME.AU3>" work for me as well as "#include "TIME.AU3""? It seems like the latter quote is mis-information.

Anyway, thank you to those who provided constructive criticism.

Share this post


Link to post
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
Sign in to follow this  
Followers 0