Search the Community
Showing results for tags 'temp files'.
-
Hello Friends, Please assist me with the script below. ScitTE SyntaxCheckProd finds no errors. However, I cannot make it find or delete any files. I am running Autoit 3.3.14.5 on Windows 10 Home X64. I have searched the forums and internet for days and can't find anything superior to my present script. My goal is to: 1. Delete folders and files recursively older than 15 days. 2. No GUI needed. 3. Do not force deletion and no confirmation needed. 4. Don't want to use forfiles. Autoit Script: #RequireAdmin #include <Date.au3> #include <File.au3> const $MAXAGE = 3 ; days global $msg = "" global $nFilesDel = 0 $retval = _FileDeleteRecursive("C:\test","*.*",$MAXAGE) func _FileDeleteRecursive($sPath, $pattern, $maxage) local $files = _FileListToArray($sPath,$pattern,1) if @error <> 0 then return -1 local $dirs = _FileListToArray($sPath,"*",2) if @error <> 0 then return -1 local $age, $nFilesFound = 0, $retval if IsArray($files) then for $n = 1 to $files[0] $age = _DateDiffInDays($sPath & "\" & $files[$n]) if $age > $maxage then _DeleteFile($sPath & "\" & $files[$n],$age) $nFilesFound += 1 endif next endif if IsArray($dirs) then for $n = 1 to $dirs[0] $retval = _FileDeleteRecursive($sPath & "\" & $dirs[$n], $pattern,$maxage) if $retval > 0 then $nFilesFound += $retval next endif return $nFilesFound endfunc func _DateDiffInDays($filename) if not FileExists($filename) then return -1 local $filetime = FileGetTime($filename) local $tempDate = $filetime[0] & "/" & $filetime[1] & "/" & $filetime[2] local $currDate = @YEAR & "/" & @MON & "/" & @MDAY return _DateDiff("D",$tempDate,$currDate) endfunc func _DeleteFile($filepath,$age) $msg = $msg & "Age: " & $age & " File: " & $filepath & @CRLF FileDelete($filepath) $nFilesDel += 1 endfunc
- 9 replies
-
- temp files
- recursively
-
(and 1 more)
Tagged with: