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

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

    I just encountered the same problem and it had to do with some files being lost or corrupted. To correct the issue, just run check disk:

    chkdsk /F e:
    

    This can be run from the search windows box or from a cmd prompt. The /F fixes any issues it finds, like recovering the files. Once this finishes running, you can delete the files and folders like normal.

    0 讨论(0)
  • 2021-01-30 02:28

    I had a similar problem, tried to delete an empty folder via windows explorer. Showed me the not empty error, so I thought I try it via admin cmd, but none of the answers here helped.

    After I moved a file into the empty folder. I was able to delete the non empty folder

    0 讨论(0)
  • 2021-01-30 02:28

    Im my case i just moved the folder to root directory like so.

    move <source directory> c:\
    

    And then ran the command to remove the directory

    rmdir c:\<moved directory> /s /q
    
    0 讨论(0)
  • 2021-01-30 02:31

    I had "C:\Users\User Name\OneDrive\Fonts", which was mklink'ed ( /D ) to "C:\Windows\Fonts", and I got the same problem. In my case

    cd "C:\Users\User Name\OneDrive"

    rd /s Fonts

    Y (to confirm the action)

    helped me. I hope, that it helps you too ;D

    0 讨论(0)
  • 2021-01-30 02:35

    What worked for me is the following. I appears like the RMDir command will issue “The directory is not empty” nearly all the time...

    :Cleanup_Temporary_Files_and_Folders
    
    Erase /F /S /Q C:\MyDir
    
    RMDir /S /Q C:\MyDir
    If  Exist  C:\MyDir  GoTo Cleanup_Temporary_Files_and_Folders
    
    0 讨论(0)
  • 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.)

    0 讨论(0)
提交回复
热议问题