Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DeleteFolder oddity

Status
Not open for further replies.

schase

Technical User
Sep 7, 2001
1,756
US
Hey folks,

This is driving me totally bonkers.

I'm running a command to delete a folder by using.
Code:
Set BDFSO = CreateObject("Scripting.FileSystemObject") 
on error resume next
response.write strText5 & "\" & strText8 & "<BR>"
BDFSO.DeleteFolder(strText5 & "\" & strText8), True
on error goto 0
set BDFSO=nothing

When that runs - it will response.write the directory like this

Code:
c:\some_place\another\last_folder
[code]

That folder is usually 3 deep with subfolders

seems great, but it freaks.  It will sometimes delete everything properly, sometimes will delete all but the main folder, sometimes the main folder and a random one or two.

If I remove the error checking, sometimes it will not give any error, sometimes it will toss a permissions error.  IUSR_machinename has full control - I also tried everyone full control.  There are no denies at all.

I've got it running in other spots that are only 2 deep and it deletes it perfectly.

Any ideas or should I try for a more robust method of cycling through each and every subfolder and each file?

Thank you 

Stuart
 
I didn't have the most reliable experience with DeleteFolder either, same sort of issues where it was performing exactly as expected but you couldn't quite put your finger on it. A suggestion for your code, might not make a big difference but:
Code:
Set BDFSO = CreateObject("Scripting.FileSystemObject")
on error resume next
response.write strText5 & "\" & strText8 & "<BR>"
[COLOR=blue]BDFSO.DeleteFolder(strText5 & "\" & strText8, True)[/color]
on error goto 0
set BDFSO=nothing
I use for a lot of reference, and the syntax they give to force deletion of read-only folders includes the True inside the parenthesis of the DeleteFolder command. It can generally be a good idea to do a check first using FolderExists before executing the DeleteFolder. Some other options would be to expand your code to read the contents of the folder first, you could also add some lines that would log the commands and results so that you could review them after the script executes, sort of checking its work until you trust it's working as you wish.
 
>I use for a lot of reference, and the syntax they give to force deletion of read-only folders includes the True inside the parenthesis of the DeleteFolder command.
Do they? That's definitively incorrect for vbs.
 
To read it, should be careful. It just copies the official ms documentation which would be the same---maybe you go check it. There is something that is tacit understanding between documentation convention and specific language scripters.
 
Thanks guys,

None of the folders were read only anyway, I tried the script both with and without the true.

What I think i'll do is run a deletefolder to wipe out most of it - maybe all. then check to see if the folder still exists and if it does, iterate through each subfolder deleting.

Strange how it works, or doesn't.





Stuart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top