Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DeleteFolder access denied

1,355 views
Skip to first unread message

IdleBrain

unread,
May 3, 2010, 9:41:14 AM5/3/10
to
Hello,
As part of a VBScript, when I am trying to run the following line of
code after using tempFolderLocation with Run(command), I get 'access
denied' error.
FSO.DeleteFolder tempFolderLocation, True
However the above line removes all individual files within that
folder.

Using process explorer from SysInternals, I found that the Vbscript
still has a file handle to tempFolderLocation. If I close the file
handle to tempFolderLocation manually just before FSO.DeleteFolder
executes, FSO.DeleteFolder runs fine without any error.

I am interested in finding out how I can close the handle to
tempFolderLocation before executing FSO.DeleteFolder.

Thanks in advance.

Pegasus [MVP]

unread,
May 3, 2010, 11:57:12 AM5/3/10
to

"IdleBrain" <indianmo...@yahoo.com> wrote in message
news:d57a1921-3b2e-4347...@x5g2000vbf.googlegroups.com...

Does the problem occur when you run this 2-line fragment of your code?
set fso=createobject("Scripting.FileSystemObject")
FSO.DeleteFolder tempFolderLocation, True

If it does not then the problem is caused by whatever code you excecute
before this fragment. You need to post it in order to get a good answer.

IdleBrain

unread,
May 3, 2010, 1:17:57 PM5/3/10
to
Yes, the problem occurs when I run: FSO.DeleteFolder
tempFolderLocation,True

I am not running any particular code from within the
'tempFolderLocation' but I am running a batch file (.cmd) within that
folder using run(command) and waiting until the batch file is
completed.

Even a sleep of 30s does not help with not getting 'access denied'
error message.

Pegasus [MVP]

unread,
May 3, 2010, 1:54:22 PM5/3/10
to

"IdleBrain" <indianmo...@yahoo.com> wrote in message

news:f32c3b35-234d-42d0...@c11g2000vbe.googlegroups.com...

Your answer is a little ambiguous and we need to be very precise here. The
questions is: Does the problem occur when you run this 2-line fragment of
your code?

set fso=createobject("Scripting.FileSystemObject")
FSO.DeleteFolder tempFolderLocation, True

In other words, does it occur when you paste these two lines into a .vbs
file, replace tempFolderLocation with an actual string, then invoke the
script?

IdleBrain

unread,
May 3, 2010, 2:52:12 PM5/3/10
to
Sorry for misunderstanding your question..
I can manually go and delete the folder without any error messages or
can run a script with just those two lines of code and have no
problem.

Pegasus [MVP]

unread,
May 3, 2010, 3:14:24 PM5/3/10
to

"IdleBrain" <indianmo...@yahoo.com> wrote in message

news:b44fc9b3-cca1-4178...@y36g2000yqm.googlegroups.com...

This is what I suspected. Your problem is caused by one of the following:
a) The code that you do not show us opens the folder you wish to delete, or
a file inside this folder.
b) Your current working directory is the folder you wish to delete.

It is impossible to say which one it is unless you post the full VB Script
code and how exactly you invoke it.

IdleBrain

unread,
May 3, 2010, 5:09:18 PM5/3/10
to
The problem, like you suggested, was that the working directory was
set to the tempFolderLocation.
As soon as I changed the working directory after I am completed with
the code execution in the tempFolderLocation, the deleteFolder method
did not complain any more about 'Access Denied'!

Appreciate your help and hats off for your insight into the problem.


0 new messages