What is an appropriate Windows command to delete a directory and its contents, whether or not they exist? In other words, if the folder exists, delete it and all its contents, and if it doesn't exist, do nothing and don't complain about it.

(Context: build script)


In a script where you first check if exists:

IF exist "directory_path" (del /s /f /q "directory_path")

If you still get output, drop a @echo off before that command.

Or simply:

del /s /f /q "directory_path"

If it doesn't exist it will do nothing.

  • f from force
  • s from subdirectories (recursive)
  • q from quiet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.