Jump to content

Loop through files in directory


Recommended Posts

I would like to loop through files in a directory and depending on the created date, move the file to a different directory based on its created date.

I know how to retrieve the created date of a file, what I do not know is how to loop through all the files in the directory one by one?

Any help appreciated.

Link to comment
Share on other sites

  • Moderators

I would like to loop through files in a directory and depending on the created date, move the file to a different directory based on its created date.

I know how to retrieve the created date of a file, what I do not know is how to loop through all the files in the directory one by one?

Any help appreciated.

_FileListToArray()

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

The autoit help file is a very useful resource to find answers to this kind of questions. Just search on loop statements and you'll most probably find your answer.

If you have any errors or questions, look on the forum and the help file, if this does not solve your question, then post a piece of code where the error occurs. People here tend to be more extended in their answers if one shows that he tried to resolve the problem himself first

In the beginning there was nothing and then even that exploded - anonymous

Link to comment
Share on other sites

Hi DMEE,

I have searched the help file for While WEnd loop statements, but I am unsure on how to loop through the array, skipping the first element?

The help file says;

$i = 0
While $i <= 10
    MsgBox(0, "Value of $i is:", $i)
    $i = $i + 1
WEnd
Link to comment
Share on other sites

I guess that the loop statement that you need is:

For ... Next or

For ... In ... Next

for example:

$array = _FileListToArray() 
For $i = 1 to $array[0] 
   statements
Next

Edit:

your code could work if you start with $i = 1 as initialisation variable. In the loop you can use the variable $i to acces the array element with $array[$i]

Edited by DMEE

In the beginning there was nothing and then even that exploded - anonymous

Link to comment
Share on other sites

Ok, i have the following code which works great, but how do I skip the first element of the array in my for next loop as it is not a file?

#Include <File.au3>
#Include <Array.au3>
#Include <_XMLDomWrapper.au3>

$xml_path_in = "\\pathto\ArchiveIn\"

$FileList = _FileListToArray($xml_path_in, "*", 1)

For $fileInf in $FileList
    MsgBox(64, "", $fileInf)
Next
Link to comment
Share on other sites

Thanks everybody for your replies.

I will use the following;

#Include <File.au3>
#Include <Array.au3>
#Include <_XMLDomWrapper.au3>

$path = "C:\Temp\"

$xml_path_in = $path & "ArchiveIn"

$FileList = _FileListToArray($xml_path_in, "*", 1)

For $i = 1 to $FileList[0]
    MsgBox(64, "", $FileList[$i])
Next
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...