Gachl
Gachl

Reputation: 75

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?

Upvotes: 6

Views: 1988

Answers (2)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38755

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

Upvotes: 10

TopBanana9000
TopBanana9000

Reputation: 898

Try something like this: https://msdn.microsoft.com/en-us/library/fyy7a5kt%28v=vs.110%29.aspx

Sometimes you need to use the Path.Combine function to properly format a file path (it'll use all the appropriate escape characters).

EDIT

Look for buildpath in this article: http://windowsitpro.com/scripting/understanding-vbscript-manipulating-files-filesystemobject

Upvotes: 1

Related Questions