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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This command prints all subdirectories in order of their last write/created time in reverse order (latest directories first):
To delete a directories’ contents, a simple
should be sufficient
If you want to process only the first result of the
DIRcommand, you can use a FOR loop in a batch file, that leaves after the first iteration.It should look something like this:
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: