Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript cannot delete folder - permission denied

Posted on 2011-03-13
7
Medium Priority
?
1,310 Views
Last Modified: 2012-05-11
I have 3 scripts that I am combining into 1, now when I run it, I get a permission denied error at line #119.  subfolder.Delete

If I run that section standalone its fine.

Here is the script.
http://pastebin.com/tfEs1TVC

I think it has something to do with 2 different sections using FSO.

Here is a folder structure that I am working with as a point of reference (several csv files in these):
 folder structure
0
Comment
Question by:totalimpact
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:Daz_1234
ID: 35127165
First comment out line 131, you do not need to re-create the object on the objFSO variable (unless you previously set it to nothing).

1. Are there any SubFolders in there?  Try amending line 117 to
If subfolder.Files.Count = 0 And subfolder.SubFolders.Count = 0 Then

Open in new window

2. Do you, or anyone on the network, have that folder open in a Windows Explorer window?

3. Have you, or anyone on the network, got a command prompt window open and the current folder in that window is the one attempting to be deleted?

4. Double check the permissions on the folder.  You know that this is not the problem, but you should double-check anyway!

Regards,
Daz.
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 35129071
try to replace line 119 with

objFSO.DeleteFolder subfolder.Path, True

/Cheers
Daniel
0
 

Author Comment

by:totalimpact
ID: 35129725
Something within the script is locking it, something in the code section above that one. Because if I try to delete it manually while the Msg box is open, its locked, but if I run that code section stand alone (lines 33-125) without all the other code, it deletes it fine.

Not sure, but the only code above that is the FTPDownload function call, which is here:
http://pastebin.com/ddcRr8SK

I can see ftp.exe launch in the task manager while the part of the code is running, and then it closes.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:totalimpact
ID: 35132741
Not sure what changed, But I now get the permission denied earlier at line 109:
 
objfso.MoveFolder Subfolder.Path,subfolder_ar

Open in new window


 I think something isnt closing properly.

0
 
LVL 13

Accepted Solution

by:
Daz_1234 earned 2000 total points
ID: 35133265
Ok, if lines 33 to 125 work when run stand-alone, then if anything is holding anything else open, it must be in lines 1 to 32.

Nothing in lines 1 to 32 even opens any objects so the only suspect is the following line:
FTPDownload (ftp_adr), (ftp_user), (ftp_pass), strDestDir, strFetchDate, (ftp_files)

So I did a quick test and when the WshShell.CurrentDirectory equals a folder that you want to delete, you will get permission denied.

Your script is fairly complex to follow exactly without an identical setup to test with, but I want to rule this out first.  The FTPDownload function sets the Current Working Directory.

Can you add a line between 108 and 109 (or the line above wherever you get the permission denied) to check if  the Wshshell.Currentdirectory is in the one being deleted.
Set AShell = CreateObject("WScript.Shell") : MsgBox AShell.CurrentDirectory,,"Current Dir:"

Open in new window


If it is, then I suggest adding at line 96 in your function here http://pastebin.com/ddcRr8SK  the following:
oFTPScriptShell.CurrentDirectory = oFTPScriptShell.ExpandEnvironmentStrings("%windir%")

Open in new window

...which  will just ensure that the current working directory is the windows folder, i.e not one that you're going to delete or move.

Regards,
Daz.
0
 

Author Comment

by:totalimpact
ID: 35133983
WOW - that did it, you deserve extra credit.
0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 35134009
Thanks for the points, glad I could help!

Daz.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question