Delete Files from a Folder

May 27, 2018 at 15:20:04
Specs: Windows Server 2012 R2
Hi All,

I have the following Batch file to Create Backup copies of a folder.

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%"

robocopy C:\qadeploy E:\Backups\%datestamp% /MIR /log:E:\Backups\Log\%datestamp%.txt

New Folders are created with date stamp ex: 20180528 every day.

I want to delete folders older than 3 days based on date stamp.

Can someone help me please


See More: Delete Files from a Folder

Report •

#1
May 27, 2018 at 22:49:12
I can never understand some people's obsession with batch files.

Do it in Windows without using a batch file.


Report •

#2
May 28, 2018 at 00:34:50
Us the "forfiles" command in your batch file. You shouldn't have too much difficulty working out the details.

https://docs.microsoft.com/en-us/wi...


Report •

#3
May 28, 2018 at 18:37:26
@Phil22

I am not obsessed with batch file i am happy to use Windows for this.

Can you please guide me as i need to schedule this to delete files older than 3 days on a regular basis


Report •
Related Solutions


Ask Question