Solved Batch Script to delete 10 days old folders...

April 23, 2013 at 07:40:05
Specs: Windows 7
Actually I write a script to copy files from 1 folder to another now I need to delete 10 days old copied folder in the same script.If anyone have idea then please help me???
I am giving my script please check..
-----------------------
REM delete the mapped drive
net use t: /delete
REM map drive t
net use t: \\xxx.xx.xx.xx\folder_name\Subfolder
REM copy all the files to Network drive
@echo off
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%-%mm%-%dd%
md F:\BACKUP\01-METHODOLOGY\%date%
xcopy /e t:\*.* F:\BACKUP\01-METHODOLOGY\%date%
REM delete the mapped drive
net use t: /delete
-----------------------

Regards,
Sagar


See More: Batch Script to delete 10 days old folders...

Report •


#1
April 23, 2013 at 10:01:32
✔ Best Answer
I've tested the following on my machine and it seems to work like you want. BE SURE TO TEST THIS BEFORE YOU USE IT FOR REAL!!!

Add the following script to what you already have and change the path to whatever folder contains the folders that need to be deleted if they are over 10 days old.

set delpath="F:\BACKUP\01-METHODOLOGY"
cd %delpath%
forfiles /s /d -10 /c "cmd /c IF @isdir == TRUE rd /S /Q @path"
EXIT


Report •

#2
April 23, 2013 at 12:32:02
I think using FORFILES /S and RD is a race condition; you're probably better off removing one.

How To Ask Questions The Smart Way


Report •

#3
April 25, 2013 at 14:24:41
hingesagar, any luck on this?

Report •

Related Solutions

#4
April 26, 2013 at 03:38:53
Yes It works...
Thanks A lot..

--
Sagar


Report •


Ask Question