Sign in to follow this  
Followers 0
masvil

FileFindNextFile

19 posts in this topic

What FileFindNextFile func does mean for "next"? How can I choise criteria order (name, date, size etc.)?

Help and search in forum doesn't help me :o

Share this post


Link to post
Share on other sites



Stick all that information into an array? That sounds like it would take an awfully long time... maybe someone has something with using dos or something


[center]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.[/center]

Share this post


Link to post
Share on other sites

"Returns a filename according to a previous call to FileFindFirstFile."

Look up FileFindFirstFile as well.

Share this post


Link to post
Share on other sites

Look up FileFindFirstFile as well.

FileFindFirstFile defines a file search string, a kind of "filter". My question is: in which order does FileFindNextFile process files filtered by FileFindFirstFile?

Share this post


Link to post
Share on other sites

Oh, now I understand your question. My guess, since I'm not 100% certain, would be that it finds the first file that matches your criteria starting at the base location, and then goes file by file and folder by folder until it has searched through the entire base directory.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Oh, now I understand your question.

Not yet :geek:

Example: FileFindFirstFile matches these 3 files:

- 1.txt (70k)

- 2.txt (18k)

- 3.txt (90k)

How can I make FileFindNextFile processes them in size order (3.txt then 1.txt then 2.txt) instead of name order (even if I still haven't understood which is default order)?

I hope I've been clearer.

@Valuater: not so much :o

Edited by masvil

Share this post


Link to post
Share on other sites

Well it doesn't appear that FileFindNextFile does that. So to get the largest file, just use FileGetSize and compare.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Ya'll are going in circles on this subject, as I stated, you'd have to read all that information individually and store it into an array, then pull from it what specifically you are looking for.

Or maybe someone can do it via a dos command or something, which would be much faster I'm sure.

Edit:

Example from help

$search = FileFindFirstFile("*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)

Put in that loop something like under $file-- $FileSize = $Filesize & FileGetSize($file) / 1024 & Chr(01) or something then StringSplit() it. Then you would work from the stringsplit for filesize.

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

you'd have to read all that information individually and store it into an array, then pull from it what specifically you are looking for.

OK, I'll try that way.

However... strange that it's undocumented :o

Share this post


Link to post
Share on other sites

this will do the trick

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

Dim $Location = @DesktopDir & "\"

$FileList = _FileListToArray ($Location)
If (Not IsArray($FileList)) and (@error = 1) Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
Dim $Nfile[$FileList[0]]
For $x = 1 To $FileList[0] -1
    $Temp_info = FileGetSize($Location & $FileList[$x])
    $Nfile[$x] = $Temp_info & "," & $FileList[$x]
Next

ArraySortNum($Nfile, 0)
_ArrayDisplay($Nfile, " Files Sorted by Size")


; Author - SmOke_N
Func ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        If $Ascending = 0 Then
            For $x = $i To UBound($nArray) - 1
                If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x
            Next
        Else
            For $x = $i To UBound($nArray) - 1
                If Number($nArray[$SE]) > Number($nArray[$x]) Then $SE = $x
            Next
        EndIf
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

this will do the trick

It works great, thanx :o

Anyway this question is still unanswered: in which order does FileFindNextFile process files filtered by FileFindFirstFile?

Edited by masvil

Share this post


Link to post
Share on other sites

It works great, thanx :o

Anyway this question is still unanswered: in which order does FileFindNextFile process files filtered by FileFindFirstFile?

the first file found... then the second file found etc.. etc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

the first file found... then the second file found etc.. etc

Hm, back to example.

Example: FileFindFirstFile matches these 3 files:

- 2.txt (18k)

- 1.txt (70k)

- 3.txt (90k)

In which order (and why) FileFindNextFile find each of them?

Edited by masvil

Share this post


Link to post
Share on other sites

i just did a quick and dirty test with 3 jpg files named 1,2 and 3. FileFindNextFile seems to find them in that order 1 2 3 regardless of size or date created. like i say quick and dirty. hope this helps answer your original question.

Share this post


Link to post
Share on other sites

i just did a quick and dirty test with 3 jpg files named 1,2 and 3. FileFindNextFile seems to find them in that order 1 2 3 regardless of size or date created. like i say quick and dirty. hope this helps answer your original question.

I would guess that they are copied in the order they are created and stored in the table of contents in windows.. I could be wrong though!!

Share this post


Link to post
Share on other sites

i don't want to beat a dead horse here but here's what i did. created 3 jpg files. named them 123, creation times are in that order 12:50 12:51 12:52. FileFindNextFile listed them 123. i renamed file 1 to 3 and so on, FileFindNextFile still found them 123. of course when i renamed them did i change the modified date? i forgot to look. i'm really not sure what the answer is.

Share this post


Link to post
Share on other sites

When I tried it, it found files alphabetically (as expected) no matter what.

Share this post


Link to post
Share on other sites

Hm, actually we can say that order is alphabetical in any case and can't be changed. An UDF (or an official option) could be useful to go over that limit.

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