PcExpert Posted May 22, 2008 Share Posted May 22, 2008 (edited) Hi all,Is it possible to check the number a file has. My files are named like this:001 Myfile.mp3002 Myfile.mp3003 Myfile.mp3So 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 May 22, 2008 by PcExpert Link to comment Share on other sites More sharing options...
weaponx Posted May 22, 2008 Share Posted May 22, 2008 $string = "003 Myfile.mp3" $array = StringRegExp($string, "\A\d*", 3) ConsoleWrite($array[0]) Link to comment Share on other sites More sharing options...
zorphnog Posted May 22, 2008 Share Posted May 22, 2008 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)) Link to comment Share on other sites More sharing options...
sandin Posted May 22, 2008 Share Posted May 22, 2008 #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)) Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
PcExpert Posted May 22, 2008 Author Share Posted May 22, 2008 Thanks all, works like a charm Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now