Jump to content

automatic #include based on filenames/folder


Recommended Posts

Hello,

I work together with a second person on a script.

We create functions and each function is stored in a separate file (to not disturb other functions and avoid merging and so on...)

Currently in the main script there is a #include section actually looking something like this: (of course we use better names than _func[1-3] :-) )

#include <include_func1.au3>
#include <include_func2.au3>
#include <include_func3.au3>
...

If a new function comes up, someone has to include them by a single line. Not much to do.

But I was thinking if some code like this is possible.

$FileList_Includes=_FileListToArray("include","_func*.au3",1)
_arraydisplay($FileList_Includes)
for $i=1 to ubound($FileList_Includes-1)
  #include "'&$FileList_Includes[$i]&'"
next

of course the actual line #include "'&$FileList_Includes[$i]&'" au3check :

ERROR: can't open include file "'&$FileList_Includes[$i]&'"

#include "'&$FileList_Includes[$i]&'"

than I came up with the idea to "build" the include file with a script like this:

_BUILD_MY_INCLUDE.AU3/EXE

#Include <File.au3>
#Include <Array.au3>
   local $IncludeFilename="_MY_Include.au3"
   local $IncludePath="include"
   $FileList_Includes=_FileListToArray($IncludePath&"","*.au3",1)
       ;~  _arraydisplay($FileList_Includes)
   FileOpen($IncludeFilename,2)
   for $i=1 to ubound($FileList_Includes)-1
         ConsoleWrite($FileList_Includes[$i]&@CRLF)
         FileWriteLine($IncludeFilename,'#include "'&$IncludePath&""&$FileList_Includes[$i]&'"')
   next
   FileClose($IncludeFilename)

This script creates a file named: _MY_Include.au3

#include <include_func1.au3>
#include <include_func2.au3>
#include <include_func3.au3>

and than add this with

#AutoIt3Wrapper_Run_Before=_BUILD_MY_INCLUDE.EXE

and in the main script there is onyl a single include of

#include "_MY_Include.au3"

surprisingly enough (for me) this is working, but only if I build.

Question:

If there something I could also use on "GO" in Scite without building the file?

Or something simpler than my construction? I tried as always the forum search but "include" is entry that is found "always"...

Edited by Tankbuster
Link to comment
Share on other sites

You could always change the au3.properties file command that runs the script so that it runs your _BUILD_MY_INCLUDE.EXE program instead. Then in your program have IT run the command that SciTE uses to run the wrapper to run the script.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

IIRC the #include directives are processed first, then the syntax check is done and then the resulting script is executed.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@Zedna

Tried it on the very first line of my "main" script I added the @compile line, but yes you are right it looks like the "includes" are somehow added before.

But I will build a complete demo project.....in a few minues....

EDIT: So many responses...sorry, forget this message, First I have to read the others two ....

Edited by Tankbuster
Link to comment
Share on other sites

Sorry for the double posting...

@BrewManNH

But this implements I always use the new au3.properties. And all my other projects would use the same config, correct?

Don't get me wrong, all solutions (including the non automated-standard) are working in one way or the other, but I simply thought about automate it :-)

@ALL

Thank you for the answers, it meets my expectations but not my hopes ;) .

I will try also the au3.prop thing for sure.

Link to comment
Share on other sites

I LOLed when I decided to type this up haha

You can open the file and use a hotkey to plug em in XD

#include <Array.au3>
#include <File.au3>

HotKeySet("+^{SPACE}", "_insert")
HotKeySet("{ESC}", "_exit")

Global $pathIncludes = "C:\Program Files\AutoIt3\Include\test"
Global $folderIncludes = "test"

Global $asFileList = _FileListToArray($pathIncludes, "*", 1)
_ArrayDelete($asFileList, 0)
msgbox(0,"","use CTRL + SHIFT + SPACEBAR to insert your include statements where you want them in your script" & @LF & "use ESC to exit the program once you're done")

While 1
    Sleep(100)
WEnd

Func _insert()
    For $file in $asFileList
        Send("#include <" & $folderIncludes & "" & $file & ">", 1)
        Send("{ENTER}")
    Next
    Send("{SHIFTUP}{CTRLUP}")
EndFunc

Func _exit()
    Exit
EndFunc
Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I'm not entriely sure what your goal is?

Why not just put an: #Include "Functions.au3" in the main script?

And then Functions.au3 would consist of:

#Include "Func1.au3"

#Include "Func2.au3"

#Include "Func3.au3"

Edit: Am sure you've already considered that, I don't think I understand what you're trying to accomplish...

Edited by Spiff59
Link to comment
Share on other sites

@mechaflash213

;)

Maybe this belongs to the brainstorm ......ah, wait I mean brain-tornado section. Needless to say that your suggestion blows an left top, beside the fact that the others offer a professional (sorry, but boring) answer, you should get an extra point for thinking-outside-boundaries :) .

I fear the next one will offer a speech-to-text UDF.......

Edited by Tankbuster
Link to comment
Share on other sites

He's trying to automate the building of the #include file that he uses in his script. Rather than manually entering the file names in his include file, it reads all of the files in the folder and adds the names to the file for him.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

As so many MVPs are reading, could this be a RFC?

Did no body asked ever for something like this?

import java.util.*;

to get something like

#import "include/_prefix*.au3"

Of course the include with wildcards is based on "random" file system order (like the dir command...) and may not offer a complete solution. But I'm just asking the MVPs, if this is an idea to think about....

Edited by Tankbuster
Link to comment
Share on other sites

@Tankbuster

I like that idea but I doubt Devs would be happy from such feature request.

Maybe it could be only AutoIt3Wrapper directive (and not AutoIt's directive), something like this:

#AutoIt3Wrapper_Include=include/*.au3

This directive could be executed at Run (F5) and also at Compile (F7) time.

Link to comment
Share on other sites

mechaflash, he mentioned that in the first post.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

..Maybe it could be only AutoIt3Wrapper directive (and not AutoIt's directive)...

Fine for me, as long as "my" goal is achieved...

Do I need to open a ticket on my own or may I ask you (MVP) to do it. I'm not sure which component is affected (wrapper is not listed in the component dropdown).

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