Search code examples
vbscriptfilesystemobject

VBS FileSystemObject.DeleteFolder Path does not exists, yet FileSystemObject.FolderExists is true


I'm close to going insane. I have a configuration of code in VBS and it throws an error that should be logically impossible.

Check this code: (You need at least 10 reputation to post images. Well that sure is helpful.) https://i.sstatic.net/jjNDm.png

If the folder revFolder exists, then (force) delete it. That also means if the folder does not exist, no DeleteFolder will be executed. I literally have the folder in front of me, it's there, I can see it. It was created by the same code just a few lines up. FolderExists returns true so the folder exists. Yet it throws the error "Path not found".

What is going on? This must be a bug in VBS, right?


Solution

  • .FolderExists tolerates the spurious "\", .DeleteFolder doesn't:

    >> WScript.Echo goFS.FolderExists("C:\Documents and Settings\eh\30643986\")
    >> goFS.DeleteFolder "C:\Documents and Settings\eh\30643986\"
    >>
    -1
    Error Number:       76
    Error Description:  Path not found
    >> goFS.DeleteFolder "C:\Documents and Settings\eh\30643986"
    >> WScript.Echo goFS.FolderExists("C:\Documents and Settings\eh\30643986")
    >>
    0
    >>