happy2help Posted June 29, 2010 Share Posted June 29, 2010 (edited) Hi I have a camera that records in AVI format. It doesn't put a valid date on the file it creates. It is always 31 December 2000, 00:00:00. I need to list the files, don't copy the first file (it is empty), move all the other files and rename the first file to the last file name. The files are named like this PICT0158.AVI (empty) PICT0159.AVI PICT0160.AVI PICT0161.AVI PICT0162.AVI (this is the last file, so the PICT0158.AVI file will be renamed to this filename once it has been moved) After the script has run, the only file would now be PICT0162.AVI, which used to be called PICT0158.AVI. Here is the script so far #Include <File.au3> $from = ".\DCIM\100DSCIM\" ;$to = "D:\Pictures\BikeCam\2\" $to = ".\dest\" ;If FileExists($from) = 0 Or FileExists($to) = 0 Then Exit $aFileList = _FileListToArray($from, "*", 1) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $last = $aFileList[0] For $i = 1 To $last If FileGetSize($from & $aFileList[$i]) < 100 Then ContinueLoop MsgBox(4096, "File:", $aFileList[$i]) FileMove($from & $aFileList[$i], $to) Next FileMove($from & $aFileList[1], $from & $aFileList[$last], 1) When you run it on your hard drive it runs fine because the files have different dates, but on the camera, they have the same file dates and it list them in random order like PICT0159.AVI PICT0160.AVI PICT0162.AVI PICT0158.AVI PICT0161.AVI OR PICT0161.AVI PICT0162.AVI PICT0158.AVI PICT0159.AVI PICT0160.AVI etc I need to list it in correct order so the first and last file is correct to be renamed. I have tried using FileFindFirstFile with the same results. How do I list (or just process) the files in order? Edited June 29, 2010 by happy2help Link to comment Share on other sites More sharing options...
Mat Posted June 29, 2010 Share Posted June 29, 2010 #include<Array.au3> Local $a = StringSplit("PICT0159.AVI|PICT0160.AVI|PICT0162.AVI|PICT0158.AVI|PICT0161.AVI", "|") ; Get the list _ArrayDisplay($a, "Before") _ArraySort($a) _ArrayDisplay($a, "After") The only line you really want is the _ArraySort one, but you will need the #include<Array.au3> as well. Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
niubbone Posted June 29, 2010 Share Posted June 29, 2010 Hi I'm pretty new to autoit, so this is the first solution it comes in mind to me. Since the name format of your camera files is always something like blahblha222.JPG I think you should use a mix between StringMid and StringCompare (Check help file for infos). Also, if StringCompare is "clever enough" to recognise and analyse the file names itself it may be sufficient alone. I was thinking something like you StringCompare file names to get them in the order. Link to comment Share on other sites More sharing options...
happy2help Posted June 29, 2010 Author Share Posted June 29, 2010 #include<Array.au3> Local $a = StringSplit("PICT0159.AVI|PICT0160.AVI|PICT0162.AVI|PICT0158.AVI|PICT0161.AVI", "|") ; Get the list _ArrayDisplay($a, "Before") _ArraySort($a) _ArrayDisplay($a, "After") The only line you really want is the _ArraySort one, but you will need the #include<Array.au3> as well. Mat Thank you for your help. I used the _ArraySort function. Here is my "finished" script. I compile it and use autorun.inf to run it. #Include <File.au3> #include <Array.au3> $from = ".\DCIM\100DSCIM\" $to = "D:\Pictures\BikeCam\" If FileExists($from) = 0 Or FileExists($to) = 0 Then MsgBox(4096, "PROBLEM", "Correct Folders do not exist",5) Exit EndIf $aFileList = _FileListToArray($from, "*", 1) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf _ArraySort($aFileList) _ArrayDisplay($aFileList, "After") $last = $aFileList[0] For $i = 1 To $last If FileGetSize($from & $aFileList[$i]) < 100 Then ContinueLoop FileMove($from & $aFileList[$i], $to) Next FileMove($from & $aFileList[1], $from & $aFileList[$last], 1) MsgBox(4096, "Process", "Completed!",5) 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