Hi All,
i have to delete files older than 7 days using a BAT file,
i have used below command but this command is deleting all files, but i want it should delete files older than 7 days.
forfiles /p "C:\Users\YOURUSERNAME\Downloads" /s /m *.* /c "cmd /c Del @path" /d -7
kindly please help for this.
Thanks,
Abhi
How to delete files older than 7 days using a BAT file
Moderator: DosItHelp
-
- Posts: 12
- Joined: 25 Aug 2016 04:20
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: How to delete files older than 7 days using a BAT file
This may seem like a dumb question, but do you have any files in the folder that are not older than 7 days? I don't see anything wrong with the command you're using.
-
- Posts: 12
- Joined: 25 Aug 2016 04:20
Re: How to delete files older than 7 days using a BAT file
ShadowThief wrote:This may seem like a dumb question, but do you have any files in the folder that are not older than 7 days? I don't see anything wrong with the command you're using.
Hi ShadowThief,
Yeah i have files in the folder that are not older than 7 days, the issue is its also deleting the file which is only 3 days old.
please help me for this.
Thanks,
Abhi
Re: How to delete files older than 7 days using a BAT file
I use this option quite frequently :
ROBOCOPY supports UNC paths unlike Forfiles unless you utilize NET USE:
Code: Select all
ROBOCOPY C:\source C:\destination /mov /minage:7
del C:\destination /q
ROBOCOPY supports UNC paths unlike Forfiles unless you utilize NET USE:
Code: Select all
net use Z: \\unc\path\to\my\folder
if %errorlevel% equ 0 (
forfiles /p Z: /s /m *.log /D -7 /C "cmd /c del @path"
) else (
echo "Z: is already in use, please use another drive letter!"
)
Re: How to delete files older than 7 days using a BAT file
abhishekkumarrai3 wrote:ShadowThief wrote:This may seem like a dumb question, but do you have any files in the folder that are not older than 7 days? I don't see anything wrong with the command you're using.
Hi ShadowThief,
Yeah i have files in the folder that are not older than 7 days, the issue is its also deleting the file which is only 3 days old.
please help me for this.
Thanks,
Abhi
Could you show us the output of the DIR command before you run the FORFILES command.
Thanks
Re: How to delete files older than 7 days using a BAT file
abhishekkumarrai3 wrote:ShadowThief wrote: I don't see anything wrong with the command you're using.
the issue is its also deleting the file which is only 3 days old.
please help me for this.
It's been a while. Did you sort this out?
Squashman was trying to determine your problem too.
-
- Posts: 12
- Joined: 25 Aug 2016 04:20
Re: How to delete files older than 7 days using a BAT file
foxidrive wrote:abhishekkumarrai3 wrote:ShadowThief wrote: I don't see anything wrong with the command you're using.
the issue is its also deleting the file which is only 3 days old.
please help me for this.
It's been a while. Did you sort this out?
Squashman was trying to determine your problem too.
Thank you so much to everyone..
its been sorted out...
and sorry for late reply..
Thanks,
Abhi