Jump to content
Sign in to follow this  
pendal

noob to autoit, simple question

Recommended Posts

pendal

I need to return the directories within an directory into an array to be used in a loop.

I am used to coding in PHP and Javascript.

in other words

Dim $baseDir, $dirArray

$dirArray = get directory list from $baseDir

foreach($dirArray){

do something

}

Can I have some help translating that into autoit code?

I looked through the function list and can't find anything about listing directory contents.

in PHP i would use the command scandir().

Basically I need to go into each of those directories and do file maintenance.

Thanks in advance.

-P

Edited by pendal

Share this post


Link to post
Share on other sites
LurchMan

This should work for you.

#include <File.au3>
Global $array
$array = _FileListToArray($sPath, "*", 2)  ;$sPath = path to dir, "*" is wildcard saying all files, and the 2 means return folders only
For $n = 0 To UBound ($array) - 1
;do something...
Next

Look under File Management in the help file for more information.

Edit: Added for loop code

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
pendal

Look under File Management in the help file for more information.

Thank you so much! .. this will make my friday go much faster.

Share this post


Link to post
Share on other sites
erik7426

I need to return the directories within an directory into an array to be used in a loop.

I am used to coding in PHP and Javascript.

in other words

Dim $baseDir, $dirArray

$dirArray = get directory list from $baseDir

foreach($dirArray){

do something

}

Can I have some help translating that into autoit code?

I looked through the function list and can't find anything about listing directory contents.

in PHP i would use the command scandir().

Basically I need to go into each of those directories and do file maintenance.

Thanks in advance.

-P

#Include <File.au3>
#Include <Array.au3>
$DirList = _FileListToArray(@DesktopDir, "*", 2)

For $i = 1 to $DirList[0]
    MsgBox(0,@DesktopDir,"'" & $DirList[$i] & "' is a folder located in " & @DesktopDir)
Next

;or

_ArrayDisplay($DirList)

That should do what you need...just sub @DesktopDir with whatever folder you want to search...

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.