TrashBoat

Include an au.3 @scriptDir

20 posts in this topic

#1 ·  Posted

How do i add a path to a file in Include.

I want my script to get the udf in the same folder as the script/exe:

Include "@ScriptDir/udf.au3"

can this be done?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use

#Include "udf.au3"

The help file explains the search order for <> and ""

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Then i compile the script and edit the udf it dosent update 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Why would you expect that to happen?

 Isn't compiling the same as taking the current source and creating a selfcontained executable to you?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted

Just now, Jos said:

Why would you expect that to happen?

 Isn't compiling the same as taking the current source and creating a selfcontained executable to you?

Jos

I wanted that my script would read the udf that i included and execute functions from there, but now then i  compile it seems just to take the udf read it once and dont update if it has been updated

Share this post


Link to post
Share on other sites

#6 ·  Posted

#Include is processed during compile time. So you need to re-compile your script for the changes to take effect.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

can i make it so it updates somehow? or not?

Share this post


Link to post
Share on other sites

#9 ·  Posted

Yes, but that means you need to run the script each time instead of using a compiled version.
... but why do you need this anyways?   What are you looking for to update in the script?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#10 ·  Posted

My point here is so a user can put his function in the udf.au3 file and save it launch my program and execute it via function name 

Share this post


Link to post
Share on other sites

#11 ·  Posted

or maybe there is an easier way of executing another script via a gui of some sorts

Share this post


Link to post
Share on other sites

#12 ·  Posted

10 minutes ago, Jos said:

Yes, but that means you need to run the script each time instead of using a compiled version.
... but why do you need this anyways?   What are you looking for to update in the script?

Jos

im looking to update that udf so the program can read it and recognize the newly typed functions

Share this post


Link to post
Share on other sites

#13 ·  Posted

That description  is way to vague for me to consider whether there are alternative ways.
So you really need to code script logic and can't get away with an INI file or something?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#14 ·  Posted

well ini files cant store scripts and execute them on command can they? Just tell me a way how to execute another script/compiled version of the script via a gui of sorts

Share this post


Link to post
Share on other sites

#15 ·  Posted

14 minutes ago, Jos said:

That description  is way to vague for me to consider whether there are alternative ways.
So you really need to code script logic and can't get away with an INI file or something?

Jos

Think of it like a database that can be updated by the user 

Share this post


Link to post
Share on other sites

#17 ·  Posted

9 minutes ago, Jos said:

So you want your users to update the script? ...  then as stated, simply run the script with autoit3.exe.

Jos

but the users wont have autoit installed

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

So what?  Each compiled script can act as the stub for an script and execute that.

When you want real help you will have to post a real question here with its usecase ..  else I am out.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#19 ·  Posted

Options:

Give your users an uncompiled stub that uses functions that your users can edit - distributed with AutoIt. Whether these functions are in includes or not is just a matter of housekeeping. But if compiled you are locked in to whatever the state was at compile time.

Allow your users to edit a flat file / SQLite DB that is read in by your script at run time. Your script can be compiled or not. Limitation, you can execute some AutoIt code like this:

#include <MsgBoxConstants.au3>
Opt('MustDeclareVars', 1)
Global $MyFunc = "MsgBox(4096, 'Test', 'Hello') & MsgBox(4096, 'Test', 'And me')"
Execute($MyFunc)

but you wont be able to do anything much more complex than that without writing your own script parser within your AutoIt script, and that is going to get ugly fast. 

Equally you could write some functions in your script and expose them to users to activate with parameters from a flat file using conditionals, but as Jos says, you would have to post exactly what the use case was for people to advise you appropriately on that.

What it seems to me you are asking for is a compiled program that reads in some more source code and recompiles itself to include that additional source code: That is not going to happen without more pain than just distributing AutoIt in the first place. 

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

If a user is able to write custom functions why shouldn't he be able to compile the script himself?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

  • Similar Content

    • ur
      By ur
      I have recorded a gui installation and modified the au3 file as per my requirement.
      But the problem is, whenever I try to compile the au3 file, I am getting a special character on top of the file.

      Can you suggest how to resolve this as it is appearing everytime during compilation.
      And also I am trying to include a au3 file which is separate folder so I am adding the <..\Library.au3> line.
      It is able to pick that but in that file "Library.au3" there is a file install line.
      FileInstall(".\SendMail.ps1", @ScriptDir & "\SendMail.ps1") Library.au3 is being used by many other codes in the previous folder..
      But the current file is looking for the ps1 file in current folder.
      So is there any option to tell the compiler to pick the dependent files relative to Library.au3 instead of the current code.
    • pedrit0
      By pedrit0
      Hi all.
      I have created an external au3 (a library of functions and vars) that is #included in a main script that i must compile.
      I wish that the content of the library is not merged with the main script when compiling.
      My goal is to keep the ability to modify the library even after the main exe is compiled and that these changes are effective when executing the exe.
      I guess this is not possible using the standard #include method.
      Is there a way to do that ?
      thx a lot :-)
    • xiantez
      By xiantez
      Hey AutoIT Community,
      Just wanted to know if there is a way I can #include all *.au3 files in my script without having to #include each individual .au3 file. For instance, currently I have a laundry list of #includes like this:
      #include <IE.au3>
      #include <Inet.au3>
      #include <AutoItConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <GDIPlus.au3>
      #include <GuiMenu.au3> 
      [ECT...ECT...]
      Would there be a way I could include all of the files above or all  .au3 file in a one liner? That way I do not have to burn up a bunch of lines of code for just my includes.... Your help is greatly appreciated...
    • Miliardsto
      By Miliardsto
      Is there possibility to do it like this?
      Cause as I see compiler doesn't see If statement in case of #include functions.
      It includes these two files all time.
      If $var == True Then #include 'func/funcsByTabs/main_Moda.au3' Else #include 'func/funcsByTabs/main_Others.au3' EndIf  
    • AmarokStudios
      By AmarokStudios
      Good afternoon AutoIt community!,
      I was on Stackoverflow the other day and came across this question: How To Include Files From A Directory. This got me thinking... There has to be a way to do it... After a bunch of research, I wasn't able to find anything. So, I created this UDF to dynamically include every file from the directory. Of course, there are some bugs that I'd like to fix eventually, but for the most part, it works. Simply call the main function (Shown below) right after the rest of the includes before any of your actual code, and the UDF will include all of the au3 files in the specified directory. Without further ado, here is the _includeDir UDF and how to use it!
       
      _includeDir.au3
       
      Download this code (_includeDir.au3 attached as well) and place it into the directory with your current script. Next, include it in your main file. For now, I'm going to be using one called Example.au3.
       
      #Include "_includeDir.au3" Now, include whatever else you're going to be including in this script, then call the _includeDir function. NOTE: THIS MUST BE CALLED AT THE TOP OF THE SCRIPT, BEFORE ANY CODE IS WRITTEN! THE FUNCTION FORCES THE SCRIPT TO RESTART SO PUTTING IT LATER IN THE SCRIPT WILL RE-RUN THE CODE!
       
      Example.au3
      #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include") MsgBox(0,"Example","This is just an example!") See how the function is called near the top? This is the proper use of the UDF. If you had a folder called "Directory to Include" and had a bunch of .au3 files inside of it, the function would include them all into the Example.au3 script.
      If you run the Example.au3 file now, it will most likely tell you "The directory Things to Include does not exist!". Make sure you enter the name of the directory you're trying to include. Just as a side note, when including files, you should put all of the code in the INCLUDED files inside of functions so they aren't automatically run when included. Variables can be outside of the functions so they are automatically set. Remember, if you have a variable in one included file with the same name of variable in another included file, it will be overwritten with whichever include file was included last.
       
      Anyways, if you have pointed the directory to include parameter to a folder that exists and run the Example.au3, it will generate a folder called IncludeDirUDF. It will also write a new line inside of Example.au3. It will write the line 
      on line one. Of course, you don't always want it to be written to line one, right? Maybe you want this bit of code to be written on line 3 in order to keep your code organize. Is there a way to do this? Absolutely! Simply add the line number as a second parameter to the function. For example, we want to have this bit of code written on line 3, we would set up our Example.au3 file to look like this.
      #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include", 3) MsgBox(0,"Example","This is just an example!") See how we added the 3 to the end of _includeDir? This will tell the function to write the #Include "IncludeDirUDF\loadIncludes.au3" on line 3 of Example.au3. Note, the line HAS TO EXIST in order to be written to it. For example, if your Example.au3 code only has 6 lines, and you specify to be written on line 7, it WILL NOT WORK.
       
      The code is designed to include and restart in order to process the included files. For some reason, if you want to JUST generate the included file and NOT restart, you can add one more parameter to the code. If you don't want the code to restart, simply set your code up to look like this:
      #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include", 3, False) MsgBox(0,"Example","This is just an example!") Note, if you set this last parameter to false, it will simply generate the included file and write to line 3 of Example.au3 (As specified before) and exit before the code reaches the MsgBox() and it will not be displayed.
       
      The last important thing to note: In order to re-include a different set of files, you must delete the #Include "IncludeDirUDF\loadIncludes.au3" from your main script (In this case, Example.au3) and delete the generated file, IncludeDirUDF. Now you can simply rerun Example.au3 and it will include any the dir with any changes you made to it. Only .au3 files should be in the directory you're trying to include as it will not process the other files and will generate an error.
       
      I hope this UDF helps somebody out! Comment any questions/concerns you may have and I will try to address them as soon as possible!
       
      Thanks,
      Timothy
      CEO - Amarok Studios
      _includeDir.au3