Burgs Posted May 26, 2008 Share Posted May 26, 2008 Greetings, My first post! I have a directory with a bunch of sequentially numbered .txt files, for example "C:\Myfile1, Myfile2, Myfile3...Myfile96). I'm using the FileFindFirstFile and FileFindNextFile commands to search the file for the first file and each thereafter because I want to rename and move each file into another directory location. My issue is that the files are not being found/selected in the proper order exactly. For example the commands will process in the following order: Myfile39, Myfile4, Myfile40, Myfile41 Myfile49, Myfile5, Myfile50, Myfile51...etc Thus files numbered 1-9 are chosen out of sequence. I hope that you get the idea, how can I "force" the commands to read in the correct order? Thanks in advance for any help. Link to comment Share on other sites More sharing options...
monoceres Posted May 26, 2008 Share Posted May 26, 2008 _FileListToArray() gives the file in the right order for me. But since it builds upon FileFindNextFile you should consider using _ArraySort() Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Burgs Posted May 26, 2008 Author Share Posted May 26, 2008 Thanks, I'm new to AutoIt so I'm not sure I fully understand. I should do: #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray("C:\SegFiles\BACKS\") //work with files in this Directory _ArraySort($FileList) //sort the array in ascending order correct? Link to comment Share on other sites More sharing options...
monoceres Posted May 26, 2008 Share Posted May 26, 2008 Yup, that seems correct Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Burgs Posted May 26, 2008 Author Share Posted May 26, 2008 Sorry to be a bother, but I'm using the following code to do the sort but the files are still being processed in the incorrect order as before... #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray("C:\SegFiles\BACKS\") ;sort the array in ascending order _ArraySort($FileList) ; Shows the filenames of all files in the current directory. $search = FileFindFirstFile("C:\SegFiles\BACKS\*.txt") ...do stuff to each file here ;go to next file in Directory to repeat process $file = FileFindNextFile($search) Link to comment Share on other sites More sharing options...
Prophet Posted May 26, 2008 Share Posted May 26, 2008 I think the problem is your Sorting the $FileList , but use the $search = FileFindFirstFile() to move trough the the files. You should do something with $FileList if you want to use the array aproach. #include <Array.au3> #include <File.au3> $FileList=_FileListToArray("C:\SegFiles\BACKS\") _ArraySort($FileList) For $i = 0 To UBound($FileList) -1 ;do Something with $FileList[$i] Next +==================================================================+| The Definition of Madness: Creating a GUI, with GUI automation scripts |+==================================================================+ Link to comment Share on other sites More sharing options...
Burgs Posted May 26, 2008 Author Share Posted May 26, 2008 Thanks for the replies. Am I supposed to "manually" rename the files numbered 1-9? Is there a way to insert the "0" before each number in the file name? Link to comment Share on other sites More sharing options...
Prophet Posted May 26, 2008 Share Posted May 26, 2008 $string = "test" $string = "0" & $string +==================================================================+| The Definition of Madness: Creating a GUI, with GUI automation scripts |+==================================================================+ Link to comment Share on other sites More sharing options...
Prophet Posted May 26, 2008 Share Posted May 26, 2008 (edited) BTW keen observation there Hubertus72 Edited May 26, 2008 by Prophet +==================================================================+| The Definition of Madness: Creating a GUI, with GUI automation scripts |+==================================================================+ Link to comment Share on other sites More sharing options...
monoceres Posted May 26, 2008 Share Posted May 26, 2008 Thanks for the replies. Am I supposed to "manually" rename the files numbered 1-9? Is there a way to insert the "0" before each number in the file name? Tada! #include <File.au3> #include <string.au3> $FileList=_FileListToArray("C:\SegFiles\BACKS\") For $i = 0 To UBound($FileList) -1 For $j=1 To StringLen($FileList[$i]) If StringMid($FileList[$i],$j,1)*2<>0 Then FileMove("C:\SegFiles\BACKS\"&$FileList[$i],"C:\SegFiles\BACKS\"&_StringInsert($FileList[$i],"0",$j-1)) ContinueLoop EndIf Next Next Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Burgs Posted May 26, 2008 Author Share Posted May 26, 2008 Thanks for the replies. Hubertus72 I need to do some things to the files after they are put into the new Directory, they need to be taken into another program as input and then once processed there data will need to be written into a text file with the information in the correct order...so the proper sequence will be important to me. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now