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 using FileSystemObject

Status
Not open for further replies.

talenx

Programmer
Aug 7, 2001
157
US
Hello,
I’m sure I missing something here but i just don't see it...I’m trying to delete a folder using the FileSystemObject property. for some reason it returns an error.


ERROR---------
Error Type:
Microsoft VBScript runtime (0x800A0034)
Bad file name or number
/webreports_deletefolder_update.asp, line 25



here is my code
Code:
<%
Dim objSourceDelete 
objSourceDelete=  Request.Form("fr_deletesource")


Set objFso = Server.CreateObject("Scripting.FileSystemObject")
If objFso.FolderExists(objSourceFolder) Then
'The folder exists!!
objFso.DeleteFolder(objSourceFolder)
Else
response.write "No folder found!!"
Response.Write (objSourceFolder)
End If 
%>
i have checked the path it is the FULL path to the folder. oddly i have replaced the "objSourceFolder" variable with a hard coded file path (example C:\Folder1\Folder2) and it worked just fine.
any thoughts
thanks
talenx
 
make sure you're not getting a bogus space on the request object try trimming it.
 
I wonder if maybe it is considered a "Bad Folder" if it has contents? Or maybe it is read-only?

Have you tried creating a folder, hardcoding it, then recreating the same exact folder and passing it into the script?


[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Hello all,

Can be just a typo? Correct it first.
objSourceDelete <--- objSourceFolder (_wrong_)

regards - tsuji
 
Heh, I completely missed that, good call :)

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
hey guys, thanks for the quick reply, sorry I had two variables, I was thinking it might of been a syntax issue so I created another variable and set it equal to the query. string.

though I did correct it and removed the old variable I still get the error. I checked to see if the folders where read-only objects and they weren’t.

corrected code:

Code:
<%
Dim objSourceDelete 
objSourceDelete=  Request.Form("fr_deletesource")


Set objFso = Server.CreateObject("Scripting.FileSystemObject")
If objFso.FolderExists(objSourceDelete ) Then
'The folder exists!!
objFso.DeleteFolder(objSourceDelete )
Else
response.write "No folder found!!"
Response.Write (objSourceDelete )
End If 
%>

thanks
talenx
 
can you post the actual value that is getting sent over by the form collection

e.g.
<%
Dim objSourceDelete
objSourceDelete= Request.Form("fr_deletesource")
Response.Write "Form Val Passed = " & objSourceDelete & "<br>"
Response.End


___________________________________________________________________
[sub]
The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page faq333-3811
[/sub]
 
onpnt ,

The actual value thats being passed is as follows:
"F:\MSTRWeb\WebReports\Public\NewFolder" (without the "")
thanks
talenx
 
Hello talenx,

In that case, add a line after the request.form before passing on for further processing.
Code:
objSourceDelete = replace(objSourceDelete,vbcrlf,"")
regards - tsuji

 
tsuji,
sorry no dice.
it's weird because I can write out the path if the folder it's found with the FolderExists methond, and the path looks fine though when I place the whole path with in "" in the FolderExists("PATH")or FolderDelete("PATH") it works fine.
any thoughts
thanks
talenx
 
this is what the current code looks like

Code:
<%
Dim objWack 
Dim objSourceFolder
Dim objSourceDelete 

objWack = "\"
objSourceFolder=  Request.Form("fr_deletesource") & objWack & Request.Form("fr_deletefile")
objSourceDelete = replace(objSourceFolder,vbcrlf,"")

[COLOR=green]'the above string looks like this:
'F:\MSTRWeb\WebReports\Public\NewFolder[/color]

Set objFso = Server.CreateObject("Scripting.FileSystemObject")
If objFso.FolderExists(objSourceDelete ) Then
[COLOR=green]'The folder exists!![/color]
Response.Write (objSourceDelete )
objFso.DeleteFolder(objSourceDelete )
Else
response.write "No folder found!!" 
%>
<p>
<%
Response.Write (objSourceDelete)
End If 
%>

the thing i don't get is when string is hard coded between "" it works fine.

any thoughts

thanks
talenx
 
doesn't "new folder" normally have a space? just double checking is all. also is this perchance a mapped drive?
 
yeah, i removed it just to see if that was the issue but..
I think I figured it out ...

Looks like somewhere along the way a space ' ' was being added to the end if the PATH,
"F:\MSTRWeb\WebReports\Public\NewFolder "
^
weird huh?

i later place a new variable in select string for using the objFile.PATH, posted it to the objFso.FolderExists and objFso.DeleteFolder methods and it worked.


sorry for the confusion.

thanks

talenx
 
*scratches his head* aint that what i said to start with :) just kiddin, glad you caught it!
that's the hard part about helping debug something is you're not there to see it, can be a pain in the buttox sometimes.

side note, and for future instances, use response.write "|" & Value & "|"

the "|" being a "pipe", i use this method anytime i response out a value that way i can catch anything obscure between them vertical lines.

hope it helps, glad it's working :)
 
DreXor,
Thanks for the debugging tip. Again thank you ALL for your assitance,I appreciate the patience

thanks
talenx

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top