DavidW Posted November 24, 2016 Share Posted November 24, 2016 (edited) Hi guys, I want to make a script where i delete files from a folder older then 7 days, I have googled and tried to make a script, but it doesn't seem to work. I would love to hear your improvements/ tips/ suggestions/hints to make it work C:\test is a old folder i created with some files which i want to delete #include <File.au3> #include <Date.au3> $test = _FileListToArray("C:\test") $date=@YEAR&"/"&@MON&"/"&@MDAY $date2= _DateAdd("D", -7, $date) $date3=StringSplit($date2,"") $date4= $date3[1]&$date3[2]&$date3[3]&@HOUR&@MIN&@SEC if IsArray($test) Then for $i = 1 to UBound($test) - 1 $tijd = FileGettime("C:\test" & $test [$i],0, 0) If $tijd < $date Then FileDelete($test[$i]) EndIf Next EndIf Edited November 24, 2016 by DavidW Link to comment Share on other sites More sharing options...
Malkey Posted November 24, 2016 Share Posted November 24, 2016 You could try this approach. #include <File.au3> #include <Date.au3> Local $Folder = @ScriptDir & "\" ; "C:\test\" ; $test = _FileListToArray($Folder) If IsArray($test) Then For $i = 1 To UBound($test) - 1 $tijd = StringRegExpReplace(FileGetTime($Folder & $test[$i], 0, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "${1}/${2}/${3} ${4}:${5}:${6}") ; Last modified Date If _DateDiff('D', $tijd, _NowCalc()) > 7 Then ; 'D' = Difference in days between the given dates ;FileDelete($Folder & $test[$i]) ConsoleWrite("Last modified Date " & $tijd & " Delete: " & $Folder & $test[$i] & @CRLF) EndIf Next EndIf Link to comment Share on other sites More sharing options...
DavidW Posted November 24, 2016 Author Share Posted November 24, 2016 (edited) Just now, Malkey said: You could try this approach. #include <File.au3> #include <Date.au3> Local $Folder = @ScriptDir & "\" ; "C:\test\" ; $test = _FileListToArray($Folder) If IsArray($test) Then For $i = 1 To UBound($test) - 1 $tijd = StringRegExpReplace(FileGetTime($Folder & $test[$i], 0, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "${1}/${2}/${3} ${4}:${5}:${6}") ; Last modified Date If _DateDiff('D', $tijd, _NowCalc()) > 7 Then ; 'D' = Difference in days between the given dates ;FileDelete($Folder & $test[$i]) ConsoleWrite("Last modified Date " & $tijd & " Delete: " & $Folder & $test[$i] & @CRLF) EndIf Next EndIf nvm solved my own question thanks for help! Edited November 24, 2016 by DavidW 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