Jump to content

noob to autoit, simple question


Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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