ScriptMerchant Posted May 28, 2005 Share Posted May 28, 2005 Hi guys, Im trying to write a script that backs up data for a specifc file extension if the modified date is older than 7 days from current date. Im sort of stuck . Im trying to use the values returned for the date time as the file value to copy. Also Im having a problem with the corrrect syntax for While statements, any assitance would be greatly appreciated, here is what I have so far: $search = FileFindFirstFile("c:\AutoCPyTest1\" & "*.doc") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $FileDate = FileGetTime($search, 1) WEnd if $iTodaysDate - $FileDate < 7 Then CopyFile " $FileDate" "c:\P1TestCpy\ $FileDate" $file = FileFindNextFile($search) If @error Then ExitLoop WEnd ; Close the search handle FileClose($search) Link to comment Share on other sites More sharing options...
buzz44 Posted May 28, 2005 Share Posted May 28, 2005 (edited) Perhaps this can help Edited May 28, 2005 by Burrup qq Link to comment Share on other sites More sharing options...
GaryFrost Posted May 28, 2005 Share Posted May 28, 2005 Need how your storing your date should be able to use the _DateDiff User Defined function here's your code cleaned up Had an WEnd where it didn't belong Was missing and EndIf $search = FileFindFirstFile("c:\AutoCPyTest1\" & "*.doc") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $FileDate = FileGetTime($search, 1) If $iTodaysDate - $FileDate < 7 Then CopyFile " $FileDate" "c:\P1TestCpy\ $FileDate" $file = FileFindNextFile($search) If @error Then ExitLoop EndIf WEnd ; Close the search handle FileClose($search) SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
ScriptMerchant Posted May 28, 2005 Author Share Posted May 28, 2005 Need how your storing your dateshould be able to use the _DateDiff User Defined functionhere's your code cleaned upHad an WEnd where it didn't belongWas missing and EndIf$search = FileFindFirstFile("c:\AutoCPyTest1\" & "*.doc") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $FileDate = FileGetTime($search, 1) If $iTodaysDate - $FileDate < 7 Then CopyFile " $FileDate" "c:\P1TestCpy\ $FileDate" $file = FileFindNextFile($search) If @error Then ExitLoop EndIf WEnd ; Close the search handle FileClose($search)<{POST_SNAPBACK}>Hi frost Sorry thought I included this here is how Im storing "Todays Date"#include <Date.au3>; Calculated the number of days since EPOCH (1900/01/01 00:00:00) $iTodaysDate = _DateDiff( 'D',"1900/01/01 00:00:00",_NowCalc()) Link to comment Share on other sites More sharing options...
GaryFrost Posted May 28, 2005 Share Posted May 28, 2005 (edited) I believe this is what your attempting to do #include <Date.au3> $iTodaysDate = _NowCalc() $search = FileFindFirstFile("c:\AutoCPyTest1\*.doc") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $FDate = FileGetTime($file, 1) $FileDate = $FDate[0] & "/" & $FDate[1] & "/" & $FDate[2] & " " & $FDate[3] & ":" & $FDate[4] & ":" & $FDate[5] If _DateDiff('D', $FileDate, $iTodaysDate) > 7 Then FileCopy($file, "c:\P1TestCpy\" & $file, 1) EndIf WEnd ; Close the search handle FileClose($search) Edited May 28, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
ScriptMerchant Posted May 28, 2005 Author Share Posted May 28, 2005 (edited) I believe this is what your attempting to do#include <Date.au3> $iTodaysDate = _NowCalc() $search = FileFindFirstFile("c:\AutoCPyTest1\*.doc") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $FDate = FileGetTime($file, 1) $FileDate = $FDate[0] & "/" & $FDate[1] & "/" & $FDate[2] & " " & $FDate[3] & ":" & $FDate[4] & ":" & $FDate[5] If _DateDiff('D', $FileDate, $iTodaysDate) > 7 Then FileCopy($file, "c:\P1TestCpy\" & $file, 1) EndIf WEnd ; Close the search handle FileClose($search)<{POST_SNAPBACK}>Hi, gafrost - thanks for the quick reply - Im getting the following error:---------------------------AutoIt Error---------------------------Line 18 (File "C:\FileCopyTemplate3Latest.au3"):$FileDate = $FDate[0] & "/" & $FDate[1] & "/" & $FDate[2] & " " & $FDate[3] & ":" & $FDate[4] & ":" & $FDate[5]$FileDate = $FDate^ ERRORError: Subscript used with non-Array variable.I tried modifying the line this way "$FileDate = $FDate" I also changed the FileGetTime flag to "0" for modified and changee the Diff to < 7 the script ran but the files it copied were up to a year old. Here is the current script:#include <Date.au3>$iTodaysDate = _NowCalc()$search = FileFindFirstFile("c:\AutoCPyTest1\*.doc"); Check if the search was successfulIf $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitEndIfWhile 1 $file = FileFindNextFile($search) If @error Then ExitLoop $FDate = FileGetTime($file, 0) If _DateDiff('D', $FDate, $iTodaysDate) < 7 Then FileCopy($file, "c:\P1TestCpy\" & $file, 1) EndIfWEnd; Close the search handleFileClose($search) Edited May 28, 2005 by ScriptMerchant Link to comment Share on other sites More sharing options...
GaryFrost Posted May 28, 2005 Share Posted May 28, 2005 (edited) What I posted worked hereThe following is from the help file for FileGetTimeReturn ValueSuccess: Returns an array or string that contains the file time information. See Remarks. Failure: Returns numeric 1 and sets @error to 1. RemarksThe array is a single dimension array containing six elements:$array[0]= year (four digits)$array[1] = month (range 01 - 12)$array[2] = day (range 01 - 31)$array[3] = hour (range 00 - 23)$array[4] = min (range 00 - 59)$array[5] = sec (range 00 - 59)Notice that return values are zero-padded.Also noticed you keep checking for less than 7 days diff, you 1st post said more than 7 days, to me that would mean greater ">" than, instead of less "<" than. Edited May 28, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. 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