How to solve “The directory is not empty” error when running rmdir command in a batch script?

前端 未结 13 2244
悲&欢浪女
悲&欢浪女 2021-01-30 02:16

I am making a batch script and part of the script is trying to remove a directory and all of its sub-directories. I am getting an intermittent error about a sub-directory not be

13条回答
  •  孤独总比滥情好
    2021-01-30 02:45

    Windows sometimes is "broken by design", so you need to create an empty folder, and then mirror the "broken folder" with an "empty folder" with backup mode.

    robocopy - cmd copy utility
    
    /copyall - copies everything
    /mir deletes item if there is no such item in source a.k.a mirrors source with
    destination
    /b works around premissions shenanigans
    

    Create en empty dir like this:

    mkdir empty
    

    overwrite broken folder with empty like this:

    robocopy /copyall /mir /b empty broken
    

    and then delete that folder

    rd broken /s
    rd empty /s
    

    If this does not help, try restarting in "recovery mode with command prompt" by holding shift when clicking restart and trying to run these command again in recovery mode

提交回复
热议问题