Sign in to follow this  
Followers 0
SteveGibbs

Using a batch file to delete .log older than 2 weeks

4 posts in this topic

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



#2 ·  Posted (edited)

With AutoIt you can see for FileGetTime function ! Posted Image

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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Varian

Share this post


Link to post
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0