I want to completely remove a 'folder' that may or may not be a junction to another folder. If the 'folder' isn't a junction rd /s /q 'folder' will do the job.

But if the 'folder' is a junction to another folder I found that:

In Windows XP, rd /s /q will delete the junction and everything inside the destination folder but doesn't remove the destination folder.

In Windows 7, rd /s /q will only delete the junction, and the destination folder isn't touched.

My question is, given a 'folder' that may or may not be a junction to another folder, how can I completely remove it using the command line?

  • I have been thinking about this for some time, and I can't think of an alternative to parsing the dir listing and removing the target and the link separately, according to what the entry shows. Maybe PowerShell can do a better job, but I have only the most cursory knowledge of it.
    – AFH
    Dec 17, 2017 at 21:19
  • Will using "del /f/s/q foldername > nul" then "rmdir /s/q foldername" work for you? The first command ensures there are no files and the second deletes the folder & subfolders.
    – DBADon
    Apr 22, 2019 at 0:06


Your Answer

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