Jump to content

Recommended Posts

Posted (edited)

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
Posted

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

Posted

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])
    EndIf
WEnd

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

Posted

#Include <File.au3>
#Include <Array.au3>
$directory = "d:\Music" ;directory of your mp3 files
$FileList=_FileListToArray($directory, "*.mp3", 1)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
for $i = 1 to $FileList[0]
    if $i <> 1 Then
        $compare = StringCompare ((StringLeft($FileList[$i], 3))/1, (StringLeft($FileList[$i-1], 3))/1)
        $number = $i-1
        if $compare = 0 OR $compare = -1 then ExitLoop
    EndIf
Next
MsgBox(0, "ok", "last number is number: " & StringLeft($FileList[$number], 3))

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...