SteveGibbs Posted January 25, 2011 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
wakillon Posted January 25, 2011 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.16.1 X86 - SciTE 4.4.6 - WIN 10 X64 - Other Example Scripts
Varian Posted January 25, 2011 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
JoHanatCent Posted January 26, 2011 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)
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