PERTU Posted May 4, 2010 Posted May 4, 2010 Hi, I have a folder with videos named like: DpRiley01.wmv, DpRiley02.wmv, Dallara01.wmv, Dallara02.wmv etc... I want my script to find the number of the next video I save. For example my next DpRiley video would be number 03. The way I'm trying to do it is to use _FileListToArray to put all the filename in an array, remove the last sixth character, count how many times DpRiley is in the Array and add +1 to this number. I don't know how to count how many times DpRiley is in the array. Here is my Code so far: $video = "DpRiley" $FileList=_FileListToArray("C:\Users\Olivier\Videos") If @Error=1 Then MsgBox (0,"","No Folders Found.") Exit EndIf If @Error=4 Then MsgBox (0,"","No Files Found.") Exit EndIf _ArrayTrim($FileList, 6, 1) $FileCurentVersion = "I don't know how to find it" $FileNewVersion = $FileCurentVersion + 1 MsgBox (0,"", $FileNewVersion) Thanks for helping me.
sahsanu Posted May 4, 2010 Posted May 4, 2010 (edited) You can search "DpRiley" at the same time you list the files with _FileListToArray. Take a look to the help file and pay attention to "$array[0] = Number of Files\Folders returned". I hope this helps ;-) #include <file.au3> $video = "DpRiley" $FileList=_FileListToArray("C:\Users\Olivier\Videos",$video & "*.wmv",1) If @Error=1 Then MsgBox (0,"","No Folders Found.") Exit EndIf If @Error=4 Then MsgBox (0,"","No Files Found.") Exit EndIf $FileNewVersion = $FileList[0] + 1 MsgBox (0,"", $FileNewVersion) Edited May 4, 2010 by sahsanu
Malkey Posted May 4, 2010 Posted May 4, 2010 (edited) This example works on the theory that at the start the file to be saved will be DpRiley01.wmvIf DpRiley01.wmv exists the next file name will be DpRiley02.wmvAnd again, if DpRiley02.wmv exists the next file name will be DpRiley03.wmvAnd again and again.Local $video, $sDir, $sNum, $sVideoName $video = "DpRiley" $sDir = @ScriptDir & "\"; "C:\Users\Olivier\Videos\" $sNum = 1 $sVideoName = $sDir & $video & StringRight("0" & $sNum, 2) & ".wmv" ; Edit added this "." before wmv While FileExists($sVideoName) = 1 $sNum += 1 $sVideoName = $sDir & $video & StringRight("0" & $sNum, 2) & ".wmv" WEnd ; Test:- If file exists, then number in filename is incremented on next script run. ;$file = FileOpen($sVideoName,10) ;FileClose($file) MsgBox(0, "", 'Next new video name is "' & $sVideoName & '"' & @CRLF & _ "Next number is " & StringRight("0" & $sNum, 2))Edit: Added a missing "." before first mentioned wmv extension. Edited May 4, 2010 by Malkey
PERTU Posted May 4, 2010 Author Posted May 4, 2010 Thanks to both of you. sahsanu: I tried to copy paste your code and didn't work. I tried to understand it but it is difficult. I'll try again once I'm more awake Malkey: It worked when I removed "@ScriptDir & "\"; ". Right now I understand the logic behind this code. I'll just have to go check the parameters to all functions in details to learn about this code.
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