Solved Deleting files by BATCH older than 7 days etc

Netgear / Dg834g
December 9, 2013 at 23:28:07
Specs: Windows XP, HexaCore AMD FX-6100, 1400 MHz (7 x 200) / 4gb DDR
As part of my Batch file logging I keep 2 files as accumulative error logs, one is for INTERNET related errors, and the Other is for COMPUTER related errors. My recent batch for rebooting the router works very well, however I decided that rather than getting into a LOOP situation if the error was external to my network such as due to my INTERNET Service Provider who is coming to fix a problem with my phone line on Wednesday.

I created 2 logs, which are written to depending on the fault, PC v NET, actions are taken depending on the type of error, if after 3 tries the error is not fixed the server is shut down.

However if after a few days their are no errors I want to zero them out, or delete them if older than 7 days. I like what I read about FORFILES and I downloaded forfiles.exe but it will not work on my windows XP SP3 system perhaps it has some missing DLL files ? My STATUS error log compare files are.
ustable.txt and wanout.txt

Here is my command line in test mode:
FORFILES -p"C:\State" -m*ust*.txt -d"-7" -c "cmd -c del @FILE"
forfiles -p"C:\State" -m*nout.txt -d"-7" -c "cmd -c del @FILE"

I tried all sorts of variations most just do not do anything, not even an error so I’m baffled ?
If I get the format on the line wrong I do get the HELP list from forfiles however but just no functionality of the purpose of forfiles. Need a simple solution.

Michelle

PS I finally got it working lol the format was very confusing found some tips online this works for me.

forfiles.exe -p"C:\State" -m*.txt -d-7 -c"cmd /c del /q @FILE"
Not even in English but the code was :p
http://batch.xoo.it/t3436-Programma...

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


See More: Deleting files by BATCH older than 7 days etc

Report •

#1
December 24, 2013 at 22:17:04
✔ Best Answer
Try this:

@echo off
setlocal
set "days=7"
set "tnow=%~2"
call:ftime tfile "%~1"
set /a "diff=tnow-tfile"
if %diff% LEQ %days% EXIT /b
set "attr=%~a1"
rem ECHO.%attr%, %attr:~0,1%, %~nx1 is %diff% days old
if /i "%attr:~0,1%"=="d" (
rd /Q /S "%~1"
) ELSE (
del /Q "%~1"
)
EXIT /b

Usage: <name>.bat [file/directory] [date]


Report •

#2
December 24, 2013 at 23:09:23
Dear thephantomblu

Thank you so much for your neat code I will use that :)

Michelle xoxox

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •
Related Solutions


Ask Question