Jump to content
Sign in to follow this  

See highest number

Recommended Posts

Hi all,

Is it possible to check the number a file has. My files are named like this:

001 Myfile.mp3

002 Myfile.mp3

003 Myfile.mp3

So I want my script to look for the highest number, in this case 003. When I place a file in a specified directory, (for example: myfile2.mp3) I want the script to move the file to the directory where the other files are also in and then rename it to 004 myfile2.mp3)

I Only need to know how to do the checking for the number. I've already looked at the string functions, but could find anything helpful. Thanks all!

Edited by PcExpert

Share this post

Link to post
Share on other sites

$string = "003 Myfile.mp3"
$array = StringRegExp($string, "\A\d*", 3)

Share this post

Link to post
Share on other sites

Global $sDir, $hFiles, $sFilename, $aResult, $nNext

$sDir = FileSelectFolder("Choose destination folder", "")
If StringRight($sDir, 1) <> "\" Then $sDir &= "\"

$hFiles = FileFindFirstFile($sDir & "*.mp3")
$nNext = 0

While 1
    $sFilename = FileFindNextFile($hFiles)
    If @error Then ExitLoop
    $aResult = StringRegExp($sFilename, "([0-9]+).*\.mp3", 1)
    If Not @error And UBound($aResult) >= 1 Then
        If Int($aResult[0]) > $nNext Then $nNext = Int($aResult[0])

$nNext += 1
MsgBox(0, "Information", StringFormat("The next valid number is %03d", $nNext))

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  

  • Create New...