Deleting the files and directories of an directory without deleting this root directory

Hi

With the Command Prompt in Windows 8.x, which command should I use to delete all files and all subdirectories of a directory without deleting this root directory?

Thanks

Bye

April 17th, 2015 6:43am

I have tried in this way:

del /f /s /q "<directory_path>\*"

but it does not work because all files are deleted but its nested subdirectories are not deleted. Why?

Thanks

Bye

Free Windows Admin Tool Kit Click here and download it now
April 17th, 2015 1:03pm

Hi

With the Command Prompt in Windows 8.x, which command should I use to delete all files and all subdirectories of a directory without deleting this root directory?

Thanks

Bye

April 18th, 2015 9:27am

 which command should I use to delete all files and all subdirectories of a directory without deleting this root directory?

rd /s /?  while you are in it.

Free Windows Admin Tool Kit Click here and download it now
April 20th, 2015 1:02pm

 which command should I use to delete all files and all subdirectories of a directory without deleting this root directory?

rd /s /?  while you are in it.

April 20th, 2015 5:01pm

Hi balubeto,

I am afraid there is not such a parameter to achieve your goal directly.
 With the rd command line and the parameter "/s, /q", we can easily delete all the contents include the root directory .
 As a work around ,we can make a bat file and use mkdir to recreate the root directory.
 rd /s /q folder path
 mkdir folder path

Here are links for reference of using the Del and Rd command line
Del
https://technet.microsoft.com/en-us/library/cc771049.aspx?f=255&MSPPError=-2147217396#BKMK_examples
Rmdir (rd)
https://technet.microsoft.com/en-us/library/bb490990.aspx

Best regards


Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 5:36am

 With the rd command line and the parameter "/s, /q", we can easily delete all the contents include the root directory .


Only if you are not in the root directory at the time.  If you have it open in the Command Prompt, there is a warning about that, which achieves the objective, even though a normal application of the command would delete the specified root too.
April 21st, 2015 10:18am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics