Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.) http://i.stack.imgur.com/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?

like image 560
Gachl Avatar asked Jun 04 '15 12:06

Gachl


2 Answers

.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
>>
like image 170
Ekkehard.Horner Avatar answered Dec 28 '22 11:12

Ekkehard.Horner


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

like image 25
TopBanana9000 Avatar answered Dec 28 '22 11:12

TopBanana9000