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

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

    As @gfullam stated in a comment to @BoffinbraiN's answer, the

    you are deleting itself might not be the one which contains files: there might be subdirectories in that get a "The directory is not empty" message and the only solution then would be to recursively iterate over the directories, manually deleting all their containing files... I ended up deciding to use a port of rm from UNIX. rm.exe comes with Git Bash, MinGW, Cygwin, GnuWin32 and others. You just need to have its parent directory in your PATH and then execute as you would in a UNIX system.

    Batch script example:

    set PATH=C:\cygwin64\bin;%PATH%
    rm -rf "C:\"
    

提交回复
热议问题