How to empty a folder in a command prompt? (Windows7)
Need to empty a folder in Windows 7 from the command prompt or batch file. This means deleting all the files and all sub folders and leaving the empty folder.del /s /q leaves empty subfolders so this solution doesn't work for me. I don't want to delete and recreate the folder either.
5 Answers
You can use the sdelete (Secure delete) command to clean a folder.
sdelete -s *from with in said folder to clear all of the contents.
2This command will empty the content of the current folder:
rmdir . /s /qThe only drawback is that there will be an error:
The process cannot access the file because it is being used by another process.
This could be avoided by adding a 2>nul at the end of the command:
rmdir . /s /q 2>nul Try the RMDIR (or aka the RD) command.
1RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
/S Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree.
/Q Quiet mode, do not ask if ok to remove a directory tree with /S
In a batch file:
for /D %%p IN (*) do rmdir /S /Q %%p
for %%p in (*) do del %%p See the following commands:
It will delete the whole folder:
rmdir /s /q C:\FolderName\It will create the empty folder:
mkdir C:\FolderName\ 1