Hi all,
Using CMD line, in a given directory, i want to detect the most recently created/written folder and delete all the contents of that folder... Any help/suggestions would be helpful... Thanq in advance..
Regards, chandra
Hi all,
Using CMD line, in a given directory, i want to detect the most recently created/written folder and delete all the contents of that folder... Any help/suggestions would be helpful... Thanq in advance..
Regards, chandra
This command prints all subdirectories in order of their last write/created time in reverse order (latest directories first):
DIR /A:D /O:-D /TW /B
To delete a directories' contents, a simple
DEL /S /Q "directory"
should be sufficient
If you want to process only the first result of the DIR
command, you can use a FOR loop in a batch file, that leaves after the first iteration.
It should look something like this:
@ECHO OFF
REM delete all contents from the sub directory most recently created or written to
FOR /F "delims=" %%A IN ('DIR /A:D /O:-D /TW /B') DO (
RD /S /Q %%A
EXIT /B
)
Only works for the subdirectories of the current working directory, so use with care! I guess for empty directories there will be some weird output, but I didn't test it.
EDIT:
Updated the batch file to remove the whole directory and its content using:
RD /S /Q "directory"