SteveGibbs 0 Posted January 25, 2011 Hey everyone, Does anyone know how to delete a .log file that is older than 2 weeks in a batch file. I can't seem to find out on the web. Hope it's not too off topic. Thanks Steve Share this post Link to post Share on other sites
wakillon 403 Posted January 25, 2011 (edited) With AutoIt you can see for FileGetTime function ! Example :#include <Date.au3> $_FileTime = FileGetTime ( @WindowsDir & "\explorer.exe", 1, 1 ) $_DayDiff = _DateDiff ( 'd', _ConvertTimeFormat ( $_FileTime ), _NowCalc ( ) ) MsgBox ( 4096, "", "Number of days since : " & $_DayDiff ) Func _ConvertTimeFormat ( $_FileTime ) Return StringMid ( $_FileTime, 1 , 4 ) & '/' & StringMid ( $_FileTime, 5 , 2 ) & '/' & StringMid ( $_FileTime, 7 , 2 ) & _ ' ' & StringMid ( $_FileTime, 9 , 2 ) & ':' & StringMid ( $_FileTime, 11 , 2 ) & ':' & StringMid ( $_FileTime, 13 , 2 ) EndFunc ;==> _ConvertTimeFormat ( ) Edited January 25, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Share this post Link to post Share on other sites
Varian 8 Posted January 25, 2011 (edited) Luuk mow bettuh forfiles.exe /P "PathToDirectory" /M *.log /D -15 /C "cmd /c del /q @PATH" forgot: For recursive directory search forfiles.exe /P "PathToDirectory" /S /M *.log /D -15 /C "cmd /c del /q @PATH" CAPITALS for switches are MANDATORY!!! Edited January 25, 2011 by Varian Share this post Link to post Share on other sites
JoHanatCent 13 Posted January 26, 2011 Luuk mow bettuh [CAPITALS for switches are MANDATORY!!! Very nice and handy Varian. Now to do all of this from AutoIt just use it like so!: $Location = "e:\temp2" $DaysandOlder = 14 RunWait(@COMSPEC & ' /c forfiles.exe /P ' & $location & ' /S /M *.log /D -' &$DaysandOlder & ' /C "cmd /c del /q @PATH"', '', @SW_Hide) Share this post Link to post Share on other sites