About the author

Related Articles

8 Comments

  1. 1
    BuvinJ@email.null'

    BuvinJ

    Similar to Harry Johnston’s answer, I loop until it works.

    set dirPath=C:tempmytest
    :removedir
    if exist "%dirPath%" (
        rd /s /q "%dirPath%" 
        goto removedir
    )
    
    Reply
  2. 2
    jrose@email.null'

    jrose

    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.

    Reply
  3. 3
    user7432246@email.null'

    user7432246

    What worked for me is the following. I appears like the RMDir commend will issue “The directory is not empty” on RMDir command 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

    Reply
  4. 4
    Harry

    Harry Johnston

    I’m familiar with this problem. The simplest workaround is to conditionally repeat the operation. I’ve never seen it fail twice in a row – unless there actually is an open file or a permissions issue, obviously!

    rd /s /q c:deleteme
    if exist c:deleteme rd /s /q c:deleteme
    
    Reply
  5. 5
    Thomas

    Thomas Weller

    I can think of the following possible causes:

    1. there are files or subdirectories which need higher permissions
    2. there are files in use, not only by WSearch, but maybe by your virus scanner or anything else

    For 1.) you can try runas /user:Administrator in order to get higher privileges or start the batch file as administrator via context menu. If that doesn’t help, maybe even the administrator doesn’t have the rights. Then you need to take over the ownership of the directory.

    For 2.) download Process Explorer, click Find/Find handle or DLL... or press Ctrl+F, type the name of the directory and find out who uses it. Close the application which uses the directory, if possible.

    Reply
  6. 6
    BoffinbraiN@email.null'

    BoffinbraiN

    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.)

    Reply
  7. 7
    Gobe@email.null'

    Gobe

    As @gfullam stated in a comment to @BoffinbraiN’s answer, the <dir> you are deleting itself might not be the one which contains files: there might be subdirectories in <dir> 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:cygwin64bin;%PATH%
    rm -rf "C:<dir>"
    
    Reply
  8. 8
    Daniel

    Daniel Barde

    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
    
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2017 SolutionMmyself.com