Using a batch file with the /f /r switches of the XP/2000 for command (requiring only a single statement to process it once), you can delete directories and files with a specified date and time (generally, using the creation time as the basis is more practical; if you want to use the modification time instead, remove the /t:c switch) (including long filenames with spaces).
1-A
The following deletes directories or files created on February 23, 2004 in the root directory of E
@echo off
dir e: /t:c>e:\finddate.txt
for /f "tokens=1,4* delims= " %%1 in (e:\finddate.txt) do if %%1==2004-02-23 deltree /y e:\"%%2*"
1-B
The following deletes files created on February 23, 2004 in directory E, all subdirectories, and the files in them, as follows:
@echo off
dir e: /t:c /s>e:\finddate.txt
for /f "tokens=1,4* delims= " %%1 in (e:\finddate.txt) do for /r e: %%a in ("%%2*"
do if %%1==2004-02-23 deltree %%a
(Note! When the program window shows you the directory or filename to be deleted and asks for confirmation, you must look carefully at its exact path and make sure it is the one you want to delete. Otherwise, another directory or file with the same name but a different file time may also be deleted!
If you are sure it can be deleted, or there is no other directory or file with the same name but a different file time, then you can add the /y parameter after deltree.
If you absolutely want to delete only directories or files with the specified time, it gets a bit complicated. It would be better to do it in several steps, but in the end you would still have to find them one by one.
Although the above batch file also requires you to confirm them one by one, it only takes a single statement.
If anyone can use a single statement of about the same length to delete only directories or files with the specified time, hurry up and post it!
I really hope Microsoft or someone will design and add a time parameter like the one in xcopy. That would make it much more convenient!)
*******************************************
If you want it accurate down to the hour and minute,
2-A
To delete directories or files created at 15:31 on February 23, 2004 in the root directory of E, as follows:
@echo off
dir e: /t:c>e:\findtime.txt
for /f "tokens=1,2,4* delims= " %%1 in (e:\findtime.txt) do if %%1%%2==2004-02-2315:31 deltree /y e:\"%%3*"
2-B
If you want to delete files created at 15:31 on February 23, 2004 in directory E, all subdirectories, and the files in them,
as follows:
@echo off
dir e: /t:c>e:\findtime.txt
for /f "tokens=1,2,4* delims= " %%1 in (e:\findtime.txt) do for /r e: %%a in ("%%3*"
do if %%1%%2==2004-02-2315:31 deltree %%a
(Note! When the program window shows you the directory or filename to be deleted and asks for confirmation, you must look carefully at its exact path and make sure it is the one you want to delete. Otherwise, another directory or file with the same name but a different file time may also be deleted!
If you are sure it can be deleted, or there is no other directory or file with the same name but a different file time, then you can add the /y parameter after deltree.
If you absolutely want to delete only directories or files with the specified time, it gets a bit complicated. It would be better to do it in several steps, but in the end you would still have to find them one by one.
Although the above batch file also requires you to confirm them one by one, it only takes a single statement.
If anyone can use a single statement of about the same length to delete only directories or files with the specified time, hurry up and post it!
I really hope Microsoft or someone will design and add a time parameter like the one in xcopy. That would make it much more convenient!)
1-A
The following deletes directories or files created on February 23, 2004 in the root directory of E
@echo off
dir e: /t:c>e:\finddate.txt
for /f "tokens=1,4* delims= " %%1 in (e:\finddate.txt) do if %%1==2004-02-23 deltree /y e:\"%%2*"
1-B
The following deletes files created on February 23, 2004 in directory E, all subdirectories, and the files in them, as follows:
@echo off
dir e: /t:c /s>e:\finddate.txt
for /f "tokens=1,4* delims= " %%1 in (e:\finddate.txt) do for /r e: %%a in ("%%2*"
do if %%1==2004-02-23 deltree %%a(Note! When the program window shows you the directory or filename to be deleted and asks for confirmation, you must look carefully at its exact path and make sure it is the one you want to delete. Otherwise, another directory or file with the same name but a different file time may also be deleted!
If you are sure it can be deleted, or there is no other directory or file with the same name but a different file time, then you can add the /y parameter after deltree.
If you absolutely want to delete only directories or files with the specified time, it gets a bit complicated. It would be better to do it in several steps, but in the end you would still have to find them one by one.
Although the above batch file also requires you to confirm them one by one, it only takes a single statement.
If anyone can use a single statement of about the same length to delete only directories or files with the specified time, hurry up and post it!
I really hope Microsoft or someone will design and add a time parameter like the one in xcopy. That would make it much more convenient!)
*******************************************
If you want it accurate down to the hour and minute,
2-A
To delete directories or files created at 15:31 on February 23, 2004 in the root directory of E, as follows:
@echo off
dir e: /t:c>e:\findtime.txt
for /f "tokens=1,2,4* delims= " %%1 in (e:\findtime.txt) do if %%1%%2==2004-02-2315:31 deltree /y e:\"%%3*"
2-B
If you want to delete files created at 15:31 on February 23, 2004 in directory E, all subdirectories, and the files in them,
as follows:
@echo off
dir e: /t:c>e:\findtime.txt
for /f "tokens=1,2,4* delims= " %%1 in (e:\findtime.txt) do for /r e: %%a in ("%%3*"
do if %%1%%2==2004-02-2315:31 deltree %%a(Note! When the program window shows you the directory or filename to be deleted and asks for confirmation, you must look carefully at its exact path and make sure it is the one you want to delete. Otherwise, another directory or file with the same name but a different file time may also be deleted!
If you are sure it can be deleted, or there is no other directory or file with the same name but a different file time, then you can add the /y parameter after deltree.
If you absolutely want to delete only directories or files with the specified time, it gets a bit complicated. It would be better to do it in several steps, but in the end you would still have to find them one by one.
Although the above batch file also requires you to confirm them one by one, it only takes a single statement.
If anyone can use a single statement of about the same length to delete only directories or files with the specified time, hurry up and post it!
I really hope Microsoft or someone will design and add a time parameter like the one in xcopy. That would make it much more convenient!)


