Jump to content
Sign in to follow this  
Burgs

NextFile selected is off

Recommended Posts

Burgs

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.

Share this post


Link to post
Share on other sites
monoceres

_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!

Share this post


Link to post
Share on other sites
Burgs

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?

Share this post


Link to post
Share on other sites
monoceres

Yup, that seems correct :)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Burgs

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)

Share this post


Link to post
Share on other sites
Prophet

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 |+==================================================================+

Share this post


Link to post
Share on other sites
Burgs

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?

Share this post


Link to post
Share on other sites
Prophet

$string = "test"
$string = "0" & $string


+==================================================================+| The Definition of Madness: Creating a GUI, with GUI automation scripts |+==================================================================+

Share this post


Link to post
Share on other sites
Prophet

BTW keen observation there Hubertus72 :)

Edited by Prophet

+==================================================================+| The Definition of Madness: Creating a GUI, with GUI automation scripts |+==================================================================+

Share this post


Link to post
Share on other sites
monoceres

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!

Share this post


Link to post
Share on other sites
Burgs

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.

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.