1.

Solve : Archive folder removal by date?

Answer»

I am looking to create a script that finds a folder by the time stamp. I am looking to have it find a particular file that is 7 DAYS old. We currently have an application that we keep its archived folders for 7 days but then remove the oldest directory (7 days old) every day. I am looking to automate the process but am not sure where to start on TRYING to get it to select the folder that is 7 days old. Any ideas of where I can start or how to do this? Any and all help is appreciated.you can use the for /f command , i tryed this myself ..

for /f "tokens=1,1,5* delims=," %%a in ('dir /A:D /OD /B /S') do rmdir /q /s %%a

put that in a batch file , remember that if you dont use it in a batch file ,or test it FIRST.. remove a % from all the %%a so that they become %a , this will delete the oldest folder in a directory.. not the folder thats seven days old, so only run it once a day.. and make sure that you dont use it in the c:\ directory

@ECHO OFF
CD\YOURFOLDERWITHFILES
for /f "tokens=1,1,5* delims=," %%a in ('dir /A:D /OD /B /S') do rmdir /q /s %%a
EXIT
Just to make sure I UNDERSTAND the line of code but if I just copy that into my batch file it will remove the oldest folder in the directory that I have set before it?

Quote from: Diablo416 on August 11, 2007, 04:41:40 PM



for /f "tokens=1,1,5* delims=," %%a in ('dir /A:D /OD /B /S') do rmdir /q /s %%a



Discussion

No Comment Found