Delete files on specific date
Moderator: DosItHelp
Delete files on specific date
Hi Friends,
Please can any one help to create scrip to delete all files on define date.
for example I would like to delete all files of directory "C:\test\" on date 24/10/2014.
appreciate in advance.
Please can any one help to create scrip to delete all files on define date.
for example I would like to delete all files of directory "C:\test\" on date 24/10/2014.
appreciate in advance.
Re: Delete files on specific date
You will need to create a Windows scheduled task and have it run this command in a batch file.
Code: Select all
del /q c:\test\*.*
Re: Delete files on specific date
Thanks for your reply.
My system is DOS operating system. I would make it in Autoexec.bat
My system is DOS operating system. I would make it in Autoexec.bat
Re: Delete files on specific date
Ubaid wrote:Thanks for your reply.
My system is DOS operating system. I would make it in Autoexec.bat
Which version of dos are you using?
Is it FreeDos or Microsoft MSDOS V6.22 or some other dos system?
Re: Delete files on specific date
it is MSDOS 6.22 version
Re: Delete files on specific date
Ubaid wrote:it is MSDOS 6.22 version
Then a Qbasic script with batch file is useful:
Code: Select all
@echo off
echo open "!_~_!.bat" for output as #1: a$=DATE$>!_~_!.bas
echo ? #1, "SET DAY="+RIGHT$(a$,4)+LEFT$(a$,2)+MID$(a$,4,2)>>!_~_!.bas
echo SYSTEM>>!_~_!.bas
qbasic /run !_~_!.bas
call !_~_!.bat
del !_~_!.bat
del !_~_!.bas
if %day%==20141024 deltree /y c:\test\
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Delete files on specific date
I never realized just how I easy I had it with modern batch until I tried to help with this (I did eventually get it, though).
Try this:
Note that this code assumes the output of the DATE command is in the DD-MM-YYYY format.
Try this:
Code: Select all
@echo off
REM Based on www.robvanderwoude.com/datetime.php
ver | date > temp.bat
echo set date=%%4>current.bat
call temp.bat
del temp.bat
del current.bat
echo y > y.txt
if "%date%"=="24-10-2014" del C:\test\*.* < y.txt
del y.txt
Note that this code assumes the output of the DATE command is in the DD-MM-YYYY format.
Re: Delete files on specific date
ShadowThief wrote:Code: Select all
echo y > y.txt
if "%date%"=="24-10-2014" del C:\test\*.* < y.txt
del y.txt
This also works in MSDOS
Code: Select all
echo y|del c:\test\*.*
The date variation was an issue back then too, and which is why the qbasic solution was preferable as it eliminates region differences.
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Delete files on specific date
It took me way longer than it should have to figure out a workaround for that not working in a batch script. Piping clearly works in the script, but does piping the output of an echo behave differently in DOS scripts vs on the command line?
Re: Delete files on specific date
ShadowThief wrote:does piping the output of an echo behave differently in DOS scripts vs on the command line?
Do you have an example where it failed?
I don't recall a command.com prompt being any different in that respect.
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Delete files on specific date
foxidrive wrote:ShadowThief wrote:does piping the output of an echo behave differently in DOS scripts vs on the command line?
Do you have an example where it failed?
I don't recall a command.com prompt being any different in that respect.
echo y|del c:\test\*.* didn't work (nothing was echoed to the screen and no files were deleted) when I tried putting it in the script, but it works fine on the command line.
Re: Delete files on specific date
ShadowThief wrote:echo y|del c:\test\*.* didn't work (nothing was echoed to the screen and no files were deleted) when I tried putting it in the script, but it works fine on the command line.
It works fine in my MSDOS 6.22 VM in a batch file and also on the dos prompt.
The screen output is the same too.
Which OS are you using to test it in?
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Delete files on specific date
I'm also running an MS-DOS 6.22 VM.


Re: Delete files on specific date
Add an echo to show you the IF date compare - and you are using c:\temp and not c:\test
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Delete files on specific date

It definitely should be working, and if it's working for you and not me, then there's some issue on my side. Maybe I have some syntax error where the del thinks the entire if statement is being piped into it?