ammounpierre
asked on
Delete old files based on date ?
I have files that I need to get rid of ...
But I would like to delete the files before a certain date (created).
can I specify a range ?
let's say delete files between 10Jan and 14Jan
thanks.
But I would like to delete the files before a certain date (created).
can I specify a range ?
let's say delete files between 10Jan and 14Jan
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
By the way, you can also call the batch file from within another batch file. But remember to pass it both dates as before ie,
:
CALL delrange 26/01/2008 28/02/2009
:
NOTE: I've condensed the last line.... otherwise it's the same as the code above.
@echo off
setlocal enabledelayedexpansion
set d1=%1
set d2=%2
set d1=!d1:~6,4!!d1:~3,2!!d1:~ 0,2!
set d2=!d2:~6,4!!d2:~3,2!!d2:~ 0,2!
for %%a in (*.*) do (
set fn=%%a
set fd=%%~ta
set fd=!fd:~6,4!!fd:~3,2!!fd:~ 0,2!
if !fd! GEQ !d1! if !fd! LEQ !d2! del !fn!
)
:
CALL delrange 26/01/2008 28/02/2009
:
NOTE: I've condensed the last line.... otherwise it's the same as the code above.
@echo off
setlocal enabledelayedexpansion
set d1=%1
set d2=%2
set d1=!d1:~6,4!!d1:~3,2!!d1:~
set d2=!d2:~6,4!!d2:~3,2!!d2:~
for %%a in (*.*) do (
set fn=%%a
set fd=%%~ta
set fd=!fd:~6,4!!fd:~3,2!!fd:~
if !fd! GEQ !d1! if !fd! LEQ !d2! del !fn!
)
Might also be worth looking at https://www.experts-exchange.com/questions/20947290/Delete-All-Contents-of-Folder-Older-than-7-Days.html.
Open in new window