Sign in to follow this  
Followers 0
ale1981

Loop through files in directory

10 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

Thanks for your prompt response.

How do i now loop through the files in that array, i need to loop through the array apart from the first element in the array as that is the number of files?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

For $fileInf in $FileList
  If IsString($fileInf) Then
    MsgBox(64, "", $fileInf)
  Endif
Next


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

Share this post


Link to post
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

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  
Followers 0