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

前端 未结 13 2426
悲&欢浪女
悲&欢浪女 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:41

    The reason rd /s refuses to delete certain files is most likely due to READONLY file attributes on files in the directory.

    The proper way to fix this, is to make sure you reset the attributes on all files first:

    attrib -r %directory% /s /d
    rd /s %directory%
    

    There could be others such as hidden or system files, so if you want to play it safe:

    attrib -h -r -s %directory% /s /d
    rd /s %directory%
    

提交回复
热议问题