Jump to content

Func to Return last file?


Guest fizbang
 Share

Recommended Posts

Guest fizbang

I have a bunch of files with sequentially numbered extensions. I need a function that will return the file with the highest extention, '13' in the case below. The problem is, the function returns 9 as the highest. What's wrong?

test.10

test.12

test.9

test.13

test.8

test.7

Func LastFile($ext)

$search = FileFindFirstFile("*." & $ext)

; Check if the search was successful

If $search = -1 Then

return ""

EndIf

dim $test, $file

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

$test = $file

WEnd

FileClose($search)

return $test

EndFunc

Also if I do

$x = "9"

$y = "10"

if $x > $y then

$z = "yes"

endif

$z will always be yes. Is there a way to force them to be numbers?

Link to comment
Share on other sites

This works for me:

=======================================

Dim $search, $file

Dim $ThisExt, $HighExt

$search = FileFindFirstFile("*.*")

If $search = -1 Then Exit

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

$NameParts=StringSplit($File, ".")

$ThisExt = Number($NameParts[ubound($NameParts)-1])

If $ThisExt > $HighExt Then

$HighExt = $ThisExt

$HighFile = $File

EndIf

Wend

FileClose($search)

MsgBox(0,"Results", "Max extension file = " & $HighFile)

=======================================

The poop being that ASCII "13" comes before ASCII "9". I grab the extension, convert it to a number THEN do my comparisons.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...