skysel Posted January 26, 2010 Share Posted January 26, 2010 This is the part of script I use for moving files created today. For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = @MDAY Then FileMove($srcfolder & "\" & $FileList[$i], "\\NetShare\TraceLogs") EndIf Next I would appreciate some pointers how to modify this script to move files created yesterday? Thanks in advance! Link to comment Share on other sites More sharing options...
water Posted January 26, 2010 Share Posted January 26, 2010 Please have a look at _DateAdd. This lets you calculate a new date. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 Or you could just do @MDay - 1. It works for me. For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = (@MDAY - 1) Then FileMove($srcfolder & "\" & $FileList[$i], "\\NetShare\TraceLogs") EndIf Next Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
water Posted January 26, 2010 Share Posted January 26, 2010 Are you sure? What if the script was run on the 1st of February. Then the month should be decremented as well. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 (edited) Are you sure? What if the script was run on the 1st of February. Then the month should be decremented as well. Ahh yes, I completely over looked that. I think it's the small radiation dose I just had In which case, this: #include <Date.au3> For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\NetShare\TraceLogs") EndIf Next Edit: Wrong function name Edited January 26, 2010 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
water Posted January 26, 2010 Share Posted January 26, 2010 (edited) I think you've got a lot of radiation You have to use _DateAdd (even to subtract) and compare the whole date (not just the year). So - if I haven't made a mistake - the code should look like: #include <Date.au3> For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] & "/" & $FileTime[1] & "/" $FileTime[2] = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\NetShare\TraceLogs") EndIf Next Edited January 26, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 (edited) Your code is wrong too. You're again only comparing the day, it won't ever get to the months etc. How about we just compare a string? #include <Date.au3> For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 1) If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\NetShare\TraceLogs") EndIf NextYou could also do this with the _DateDiff function:#include <Date.au3> For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 1) If _DateDiff("D", $FileTime, _NowCalcDate()) = 1 Then FileMove($srcfolder & "\" & $FileList[$i], "\\NetShare\TraceLogs") EndIf Next Edited January 26, 2010 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
skysel Posted January 26, 2010 Author Share Posted January 26, 2010 So which one is correct? Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 So which one is correct? Either of these should work for you Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
skysel Posted January 26, 2010 Author Share Posted January 26, 2010 Ok, so here is the complete script, I've modified it with your help - yet it does not work. It should move files created today and after that..files created yesterday. #Include <File.au3> #include <Array.au3> #include <Date.au3> $srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" $FileList = _FileListToArray($srcfolder) For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = @MDAY Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\Tracelogs") EndIf If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\TraceLogs") EndIf Next Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 That would be because in my example I set FileGetTime to return a string. All you need to do is re-set the variable to the new FileGetTime everytime you go through the loop:#Include <File.au3> #include <Array.au3> #include <Date.au3> $srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" $FileList = _FileListToArray($srcfolder) For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = @MDAY Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\Tracelogs") EndIf $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 1) If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\TraceLogs") EndIf Next Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 26, 2010 Share Posted January 26, 2010 Hi, #include <Array.au3> #include <Date.au3> #include <File.au3> ;Root folder $sourceFolder = @ScriptDir & '\' ;Gather files into an array $fileList = _FileListToArray($sourceFolder, "*", 1) Dim $found[1] ;Loop through array For $X = 1 To $fileList[0] ;Retrieve creation time of file $Date = FileGetTime($sourceFolder & "\" & $fileList[$X], 1, 0) ;Format date for use with Date UDF $fDate = StringFormat("%s/%s/%s %s:%s:%s", $Date[0], $Date[1], $Date[2], $Date[3], $Date[4], $Date[5]) ;Calculate age, remove files older than seven days If _DateDiff('d', $fDate, _NowCalc()) > 7 Then ; the time ; here the doing ;FileDelete($sourceFolder & "\" & $fileList[$X]) _ArrayAdd($found, $sourceFolder & $fileList[$X]) ;MsgBox(1, "Files deleted:", $fileList[$X], 1) EndIf $found[0] = UBound($found) Next _ArrayDisplay($found) Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
skysel Posted January 26, 2010 Author Share Posted January 26, 2010 That would be because in my example I set FileGetTime to return a string. All you need to do is re-set the variable to the new FileGetTime everytime you go through the loop:#Include <File.au3> #include <Array.au3> #include <Date.au3> $srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" $FileList = _FileListToArray($srcfolder) For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = @MDAY Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\Tracelogs") EndIf $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 1) If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\TraceLogs") EndIf Next Hey James, for some reason it still won't work. Any other thoughts? Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 Hey James, for some reason it still won't work. Any other thoughts? Very strange. Which one doesn't work? Try this: #Include <File.au3> #include <Array.au3> #include <Date.au3> $srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" $FileList = _FileListToArray($srcfolder) For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = @MDAY Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\Tracelogs") EndIf $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 1) ConsoleWrite("->File time: " & $FileTime & @CRLF) If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\TraceLogs") EndIf Next Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
water Posted January 26, 2010 Share Posted January 26, 2010 (edited) Yes, but $FileTime returns YYYYMMDDHHMMSS and _DateAdd returns YYYY/MM/DD[ HH:MM:SS] (according to the help file). As I understand it they have to be converted to another format so you can compare them. Edited January 26, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 Don't want to be pedantic, but ... My code works just fine as soon as you enter a "&" in line 5. I concatenate Year, Month and Day from Filegettime and compare it to the date returned by _DateAdd.Which is what setting the flag in FileGetTime does. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 What about this then?#Include <File.au3> #include <Array.au3> #include <Date.au3> $srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" $FileList = _FileListToArray($srcfolder) For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime = _NowCalcDate() Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\Tracelogs") EndIf If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\TraceLogs") EndIf Next Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
skysel Posted January 26, 2010 Author Share Posted January 26, 2010 Still not working. I have full permissions to read/write to/from folders specified in this script. Any more thoughts? What about this then?#Include <File.au3> #include <Array.au3> #include <Date.au3> $srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" $FileList = _FileListToArray($srcfolder) For $i = 1 To UBound($FileList) - 1 $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0) If $FileTime = _NowCalcDate() Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\Tracelogs") EndIf If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then FileMove($srcfolder & "\" & $FileList[$i], "\\Netshare\TraceLogs") EndIf Next Link to comment Share on other sites More sharing options...
James Posted January 26, 2010 Share Posted January 26, 2010 Try waters post then. If that helps awesome Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
water Posted January 26, 2010 Share Posted January 26, 2010 This works (on a german system) - has been tested and returns some debugging information on the console:#Include <File.au3> #include <Array.au3> #include <Date.au3> $srcfolder = "C:\temp" $FileList = _FileListToArray($srcfolder) For $i = 1 To UBound($FileList) - 1 $FileTimeArray = FileGetTime($srcfolder & "\" & $FileList[$i]) $FileTime = $FileTimeArray[0] & "/" & $FileTimeArray[1] & "/" & $FileTimeArray[2] ConsoleWrite("Filetime: " & $FileTime & " DateAdd: " & _DateAdd("D", -1, _NowCalcDate()) & @CRLF) If $FileTime = _DateAdd("D", -1, _NowCalcDate()) Then ConsoleWrite($FileList[$i] & " was modified yesterday" & @CRLF) EndIf Next My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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