
The entire folder tree to such a folder cannot be deleted if a folder is used as the current directory for any running process.įiles currently opened by any running process with file access permissions set on file open to prevent deletion of the file while opened by the running application/process. The system attribute does never prevent deletion of a file or folder.įolders used as the current directory for any running process. The command RD with the options /Q and /S removes a directory quietly with all subdirectories even if the specified directory contains files or folders with hidden attribute or with read-only attribute set.

The next command RD is executed only if changing current directory for current command process to specified directory was successful, i.e. This error message is suppressed by redirecting it with 2>nul to device NUL. The system cannot find the path specified. PUSHD outputs following error message to handle STDERR if the specified directory does not exist at all: This works also for UNC paths by default because of command extensions are enabled by default and in this case PUSHD creates a temporary drive letter that points to that specified network resource and then changes the current drive and directory, using the newly defined drive letter. The first command PUSHD pushes current directory path on stack and next makes %PathToFolder% the current directory for running command process. This command line contains three commands executed one after the other. The simple single command line solution which of course can be also used in a batch file: pushd "%PathToFolder%" 2>nul & ( rd /Q /S "%PathToFolder%" 2>nul & popd ) That's the reason for posting one more answer with a very simple single command line to delete all files and subfolders of a folder as well as a batch file with a more complex solution explaining why all other answers as posted on using DEL and FOR with RD failed to clean up a folder completely. None of the answers as posted on, with the exception of the single command line posted by foxidrive, really deletes all files and all folders/directories in %PathToFolder%.
