Jump to content

How I Organize My UDFs


noellarkin
 Share

Recommended Posts

When I started using AutoIt, I used to dump all the community UDFs as well as my own frequently-used scripts into C:\Program Files (x86)\AutoIt3\Include - - terrible idea, of course, and I wouldn't advise anyone to do this.

These days I have the following folder structure for UDFs:

- I have a folder C:\AutoIt which has subfolders:

- - C:\AutoIt\MyLibraries, which has my own scripts, organized as C:\AutoIt\MyLibraries\MyUDFName\MyUDFName.au3

- - C:\AutoIt\CommunityLibraries, which has scripts from other forum members, organized as:
     C:\AutoIt\CommunityLibraries\CommunityMemberUsername\UDFName\UDFName.au3

For example, I've been playing around with TheXman's "jq" UDF, and this is the storage path:
image.png.6a38dc5b8dc042573fc90e2287af3a33.png

 

This in itself won't make everything run. Some UDFs will have hardcoded DLL paths which you'll have to edit. And finally, you'll have to make registry edits so you can #include these UDFs without entering the entire path.

Here's what I did:
 

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

Global Const $CUSTOMINCLUDE_REGKEYNAME = "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt"
Global Const $CUSTOMINCLUDE_REGKEYVALUENAME = "Include"
Global Const $CUSTOMINCLUDE_REGKEYVALUETYPE = "REG_SZ"
Global Const $FOLDER_COMMUNITYLIBRARIES = "C:\AutoIt\CommunityLibraries"
Global Const $FOLDER_MYLIBRARIES = "C:\AutoIt\MyLibraries"

Global $CUSTOMINCLUDE_REGKEYVALUE = ""


Local $CommunityUsers = _FileListToArray($FOLDER_COMMUNITYLIBRARIES, "*", $FLTA_FOLDERS, False)
_ArrayDelete($CommunityUsers, 0)
Local $CommunityLibraries = 0
Local $UDFPath = ""

For $i = 0 To UBound($CommunityUsers) - 1
    $CommunityLibraries = _FileListToArray($FOLDER_COMMUNITYLIBRARIES & "\" & $CommunityUsers[$i], "*", $FLTA_FOLDERS, False)
    _ArrayDelete($CommunityLibraries, 0)
    For $j = 0 To UBound($CommunityLibraries) - 1
        $UDFPath = $FOLDER_COMMUNITYLIBRARIES & "\" & $CommunityUsers[$i] & "\" & $CommunityLibraries[$j]
        If FileExists($UDFPath) Then $CUSTOMINCLUDE_REGKEYVALUE &= $UDFPath & ";"
    Next
Next

Local $MyLibraries = _FileListToArray($FOLDER_MYLIBRARIES, "*", $FLTA_FOLDERS, False)
_ArrayDelete($MyLibraries, 0)
For $j = 0 To UBound($MyLibraries) - 1
    $UDFPath = $FOLDER_MYLIBRARIES & "\" & $MyLibraries[$j]
    If FileExists($UDFPath) Then $CUSTOMINCLUDE_REGKEYVALUE &= $UDFPath & ";"
Next

$CUSTOMINCLUDE_REGKEYVALUE = StringTrimRight($CUSTOMINCLUDE_REGKEYVALUE, 1)

ConsoleWrite($CUSTOMINCLUDE_REGKEYVALUE)
RegWrite("HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt", "Include", "REG_SZ", $CUSTOMINCLUDE_REGKEYVALUE)

This script scans the "CommunityLibraries" and "MyLibraries" folders and adds all the folder paths where the folder name matches the au3 file name to the registry. So far, it has worked out great for me, because now I can use this:

#include <jq.au3>

instead of:

#include "C:\AutoIt\CommunityLibraries\TheXman\jq\jq.au3"

Okay, that's all, I hope this'll be useful for newbies who want an easy system for storing their UDFs :)

 

Link to comment
Share on other sites

I created a directory named "MyUDFs" and used SciTE Config to have AutoIt search this directory as well.
I spread my UDFs all over the place and simply added a

#include "Path\xx.au3"

where xx stands for the name of the UDF.

So there is a central point where AutoIt can find all my UDFs. Each of this UDFs just has to hold the "real" #include statement.

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

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

×
×
  • Create New...