#include <Date.au3>
#include <File.au3>
$path = "C:\Temp"
$delta = "7"
$flag = 1
$aReturn = _FileSearch($path, '*.*')
For $i = 1 To UBound($aReturn) - 1
$aTime = FileGetTime($aReturn[$i], $flag)
If _DateDiff('D', $aTime[0] & '/' & $aTime[1] & '/' & $aTime[2], _NowCalc()) > $delta Then
FileDelete($aReturn[$i])
EndIf
Next
_DirRemoveEmptyTime($path)
Func _FileSearch($sPath, $sFileMask)
Local $sOut = StringToBinary("0" & @CRLF, 2), $aOut
Local $hDir = Run(@ComSpec & ' /U/C DIR "' & $sPath & '\' & $sFileMask & '" /S/B/A-D', @SystemDir, @SW_HIDE, 6)
While 1
$sOut &= StdoutRead($hDir, False, True)
If @error Then ExitLoop
WEnd
$aOut = StringRegExp(BinaryToString($sOut, 2), "[^\r\n]+", 3)
If @error Then Return SetError(1)
$aOut[0] = UBound($aOut) - 1
Return $aOut
EndFunc
Func _DirRemoveEmptyTime($sDIR)
Local $iPRC, $aDIR = _FileListToArray($sDIR, '*', 2)
If IsArray($aDIR) Then
For $i = 1 To $aDIR[0]
_DirRemoveEmptyTime($sDIR & "\" & $aDIR[$i])
Next
EndIf
If DirGetSize($sDIR) = 0 Then
$aTimeDIR = FileGetTime($sDIR, $flag)
If _DateDiff('D', $aTimeDIR[0] & '/' & $aTimeDIR[1] & '/' & $aTimeDIR[2], _NowCalc()) > $delta Then
DirRemove($sDIR)
EndIf
EndIf
EndFunc