PERTU Posted June 21, 2007 Share Posted June 21, 2007 Hi, I have several files named like this MI01sc001.001.fla, MI01sc001.002.fla, MI01sc002.001.fla etc. What the filename means is: MI01 = Episode 01 sc001 = Scene 001 .001 = Version 001 .fla = Flash file I want to write a script that looks for scenes that have more than one version, and move every older version in a subfolder named "Old". For example I would want the script to move MI01sc001.001.fla to "Old" and keep MI01sc001.002.fla and MI01sc002.001.fla in the current folder. I don't know how to find wich files are older version. Here is what I got so far: CODE#Include <File.au3> #Include <Array.au3> ;Set working directory $dir = FileSelectFolder("Choose a folder.", "") FileChangeDir($dir) ;Create subfolder "Old" DirCreate($dir &"\old") ;Find Old version of files $FileList=_FileListToArray($dir) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf _ArrayDisplay($FileList,"$FileList") I don't want someone to write the script for me, but if anyone have some pointer to get me in the right direction I'd like to hear about it. Thank you, Olivier Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2007 Share Posted June 22, 2007 Here is what I got so far: oÝ÷ Ù.ßÛÞZ²Ö«´Ú0Ê°j{Zÿ5ìm)¶-za® Ø^jºÚÉ«¢+Ù½ÈÀÌØí¸ôÄQ¼ÀÌØí¥±1¥ÍÑlÁtìlÁtô±¥¹½Õ¹Ð(5Í ½à ØаÅ×t;Current file:", $FileList[$n]) NextoÝ÷ ØéåÊ)ìµæ¡ö©¢©¶!£ayø¥zv¦{*.Á©í¶©¦²¢ê墶jwfjGuç"²*'¶¨½è¢¹èµ:¡×«e¢Ê¦ºË[yÉ^jº'¶§jh§Ê'½éíè¯kºW¬ßÛajÖ©¦¡ë"´Öا{¶ªºe¶Økyçb+oz»"¢yî·«×åj«¨´ì£*.ë-r^jÉWîËb¢{h¦ée¶ëޮȨ{¦mêèºÖ®¶sbb33cµfW$çVÒÒôvWEfW$çVÒb33c´fÆTÆ7E²b33c¶åÒ ¤gVæ2ôvWEfW$çVÒb0ÌØíÍ%¹ÁÕФ(IÑÕɸMÑÉ¥¹5¥ ÀÌØíÍ%¹ÁÕаMÑÉ¥¹1¸ ÀÌØíÍ%¹ÁÕФ´Ø°3) EndFuncoÝ÷ Ù.Â)ej[(ç¶W§jg¦{¬¶¯z»"¢x§~®¶sbb33cµ66VæTæÖRÒ7G&æuG&Õ&vBb33c´fÆTÆ7E²b33c¶åÒÂr Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PERTU Posted June 22, 2007 Author Share Posted June 22, 2007 Thank you PsaltyDS. You really given me a lot. I tried to make it work, but I don't know how to use fonction, so I tried to use a variable instead and this part seems to work. You lost me at this line: If StringTrimRight($FileList[$i], 7) = $SceneName Then I don't know what $i is supposed to represent and where do you get the data to put into this variable. I've update my code and incorporated big part of yours. Here's what I got so far: CODE; Script Start - Add your code below here #Include <File.au3> #Include <Array.au3> ;Set working directory $dir = FileSelectFolder("Choose a folder.", "") FileChangeDir($dir) ;Create subfolder "Old" DirCreate($dir &"\old") ;Find Old version of files $FileList=_FileListToArray($dir) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf _ArrayDisplay($FileList,"$FileList") ;For/Next loop to step through the array: For $n = 1 To $FileList[0] ; [0] = line count ; MsgBox(64, "Current file:", $FileList[$n]) ;Next ;Small function to pull the version number out: #cs Func _GetVerNum($sInput) Return StringMid($sInput, StringLen($sInput) - 6, 3) EndFunc $VerNum = _GetVerNum($FileList[$n]) #ce $VerNum = StringMid($FileList[$n],StringLen($FileList[$n]) - 6, 3) ;File name minus the version info $SceneName = StringTrimRight($FileList[$n], 7) ;Find $SceneName with a greater $verNum, then move it: If StringTrimRight($FileList[$i], 7) = $SceneName Then If _GetVerNum($FileList[$i]) > $VerNum Then FileMove($dir & "\" & $FileList[$n], $dir & "\old\" & $FileList[$n]) ExitLoop EndIf EndIf Next If you could enlighted me about this $i, I might be able to make it works. thanks a lot. Olivier. Link to comment Share on other sites More sharing options...
DW1 Posted June 22, 2007 Share Posted June 22, 2007 the $i is because $FileList is an array AutoIt3 Online Help Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 22, 2007 Share Posted June 22, 2007 I tried to make it work, but I don't know how to use fonction, so I tried to use a variable instead and this part seems to work. You lost me at this line: If StringTrimRight($FileList[$i], 7) = $SceneName Then I don't know what $i is supposed to represent and where do you get the data to put into this variable. I've update my code and incorporated big part of yours. Here's what I got so far: If you could enlighted me about this $i, I might be able to make it works. A function is like GOSUB in a batch file (if that doesn't help, ignore it). It is declared elsewhere in the script (by convention, they are all stacked up at the end), and can be called anywhere else. Usually they are more complicated than _GetVerNum(), so you could just put that line of code in there anywhere you would use _GetVerNum(). For the educational value, I put it back in. What you missed in the logic was that there are two For/Next loops, one "nested" inside the other. Both For/Next loops are cycling through the same $FileList array, but they are not both looking in the same place. The "outer" loop is looking at element $n of the array, and the "inner" loop is looking at element $i. So, the file name pointed to by $n is compared to all of the file names (one at a time, by $i), and if a matching name ($SceneName) with a higher version number is found, then the one pointed to by $n gets moved to ".\old\". Follow though it here: ; Script Start - Add your code below here #Include <File.au3> #IncludH Ð^K]LÉÝÂÔÙ]ÛÜÚ[ÈXÝÜBÌÍÙH[TÙ[XÝÛ ]÷C´6ö÷6RföÆFW"âgV÷C²ÂgV÷C²gV÷C²¤fÆT6ævTF"b33c¶F" £´7&VFRÕ½±ÈÅÕ½Ðí=±ÅÕ½Ðì)¥É ÉÑ ÀÌØí¥ÈµÀìÅÕ½ÐìÀäÈí½±ÅÕ½Ðì¤((Find Old version of files $FileList = _FileListToArray($dir) If @ÜHH[SÙÐÞ ][ÝÉ][ÝË ][ÝÓÈ[ÉÌLÑÛÈÝ[V÷C² W@¤VæD`¥ô'&F7Æb33c´fÆTÆ7BÂgV÷C²b33c´fÆTÆ7BgV÷C²(í½È½9áб½½ÀѼÍÑÀÑ¡É½Õ Ñ¡¥±Ìè)½ÈÀÌØí¸ôÄQ¼ÀÌØí¥±1¥Í[0] ; [0] = line count ; Get just 3-digit version number $VerNum = _Ù][J ÌÍÑ[SÝÉÌÍÛJBBNÑÙ][H[YHZ[ÈHÚ[Û[Âb33cµ66VæTæÖRÒ7G&æuG&Õ&vBb33c´fÆTÆ7E²b33c¶åÒÂr ´f÷"ôæWB½½ÀѼ¥¹¹ä½Ñ¡ÈÀÌØíM¹9µÝ¥Ñ ÉÑÈÀÌØíÙÉ9Õ´°($ì¥Ñere is, then move the earlier one: For $i = 1 To $FileList[0] ÈYH[H[YHÚ]Ý][XX]ÚËBRYÝ[Õ[TYÚ ÌÍfÆTÆ7E²b33c¶ÒÂrÒb33cµ66VæTæÖRFVà ²bFW&R&RÆFW"fW'6ö̽ѡ͵¥±¸¸¸($$%%}ÑYÉ9Õ´ ÀÌØí¥±1¥ÍÑlÀÌØí¥t¤ÐìÀÌØíerNum Then ; Move the earlier one to \old\... FileMove(&#ÍÙ [È ][ÝÉÌLÉ][ÝÈ [È ÌÍÑ[SÝÉÌÍÛK ÌÍ٠ײgV÷C²b3#¶öÆBb3#²gV÷C²fײb33c´fÆTÆ7E²b33c¶åÒ WDÆö÷$$%¹%($%¹%(%9áÐ)9áÐ(((íMµ±°Õ¹Ñ¥½¸Ñ¼ÁÕ±°Ñ¡ÙÉÍ¥½¸¹ÕµÈ½Õ: Func _GetVerNum($sInput) Return StringMid($sInput, StringLen(&ÌÍÜÒ[] HH ÊB[[ÈÏOIÝ×ÑÙ][ Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PERTU Posted June 26, 2007 Author Share Posted June 26, 2007 Hey PsaltyDS,I wasn't around for a couple of days because June 24 is "Fête Nationale du Québec" here in Québec.I tested your script and it works exactly as needed. I'm in the process of trying to understand all the logic in the nested Loop you talked about. I might ask questions if I'm still stuck in the logic. I think it is really important for me to understand this if I want to start writing more complex script than what I was doing before.Thanks a lot.Olivier. 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