Search code examples
cmdcommand-prompt

How to delete folders in program files folder using cmd


I'm using cmd to run a software installation cycle. The steps are install - uninstall - delete associated folders - install new version.

The installation adds folders in C:\Program Files so I need to delete these folders. However, cmd returns "The system cannot find the file specified."

The code is rmdir C:\Program Files\folder /s /q. If it's not in C:\Program Files, the folder can be deleted. So I assume something is protecting these folders even though I'm running the cmd as administrator. How to delete folders in program files folder using cmd?


Solution

  • Spaces in command line commands are used to separate arguments. When you have a space in an argument (like the space in the folder name "Program Files"), you need to use quotes or escaping like the following:

    rmdir "C:\Program Files\folder" /s /q