Jump to content

Recommended Posts

Posted

Hi, I'm trying to use FileFindFirstFile and NextFile to change a set of filenames that have letters followed by numbers as the filename.

eg. apple1.txt, apple2.txt, apple12.txt, apple16.txt, apple23.txt

I want to change the filenames whilst retaining the order: apple1.txt, apple2.txt, apple3.txt, apple4.txt, apple5.txt, but the FileFindNextFile function returns the files in the order: apple1.txt, apple12.txt, apple16.txt, apple2.txt, apple23.txt.

Is there a workaround that'll get the function to return the searches in the "correct" order (like how windows explorer would display the files).

Posted

Hi, I'm trying to use FileFindFirstFile and NextFile to change a set of filenames that have letters followed by numbers as the filename.

eg. apple1.txt, apple2.txt, apple12.txt, apple16.txt, apple23.txt

I want to change the filenames whilst retaining the order: apple1.txt, apple2.txt, apple3.txt, apple4.txt, apple5.txt, but the FileFindNextFile function returns the files in the order: apple1.txt, apple12.txt, apple16.txt, apple2.txt, apple23.txt.

Is there a workaround that'll get the function to return the searches in the "correct" order (like how windows explorer would display the files).

I don't know about an option for the sort order, but you could do it yourself by string manipulation:

#include <array.au3>
#include <string.au3>

Dim $avFiles[5] = ['apple1.txt', 'apple12.txt', 'apple16.txt', 'apple2.txt', 'apple23.txt']
_ArrayDisplay($avFiles, "Before")

For $n = 0 To UBound($avFiles) - 1
    $Num = _StringBetween($avFiles[$n], "apple", ".txt")
    $avFiles[$n] = "apple" & StringFormat("%03u", $Num[0]) & ".txt"
Next
_ArraySort($avFiles)
_ArrayDisplay($avFiles, "After")

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
×
×
  • Create New...