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

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

    I experienced the same issues as Harry Johnston has mentioned. rmdir /s /q would complain that a directory was not empty even though /s is meant to do the emptying for you! I think it's a bug in Windows, personally.

    My workaround is to del everything in the directory before deleting the directory itself:

    del /f /s /q mydir 1>nul
    rmdir /s /q mydir
    

    (The 1>nul hides the standard output of del because otherwise, it lists every single file it deletes.)

提交回复
热议问题