Delete Dynamically Named Folder
Question:
How can I delete a dynamically named folder with the record it belongs to?
I created a member site that uses Pure ASP Upload to create a dynamically named folder for each member's images when they first upload. Sometimes we need to delete a member and want to delete the folder as well. Not all members upload images so not all members have folders. How can I delete the folders with the deleted record and insure the page doesn't crash when there is no folder?
Answer:
1. Create a hidden form field with the foldername as the value.
2. Insert the following code:
<%
' Delete folder with record
If (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "") Then
Set fso = CreateObject("Scripting.FileSystemObject")
folderpath = Server.MapPath("..\Uploads") 'change to the name the uploads root folder.
folderpath = folderpath & "\" & (request.form("hiddenfield")) 'change to the name of your hidden field.
If fso.FolderExists(folderpath) Then
Set folderObject = fso.GetFolder(( folderpath) & "\")
folderObject.Delete
end if
Set folderObject = Nothing
Set fso = Nothing
End if
%>
Comments
no error no work
ihave change it like his but it doesnt wors!no error no work!
<%
' Delete folder with record
If (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "") Then
Set fso = CreateObject("Scripting.FileSystemObject")
folderpath = Server.MapPath("userpics") 'change to the name the uploads root folder.
folderpath = folderpath & "\" & (request.form("del_folder")) 'change to the name of your hidden field.
If fso.FolderExists(folderpath) Then
Set folderObject = fso.GetFolder(( folderpath) & "\")
folderObject.Delete
end if
Set folderObject = Nothing
Set fso = Nothing
End if
%>
mrx3m@hotmail.com for your suggestions!thnx
RE: no error no work
RE: RE: no error no work
dynamic folder name from recordset
James Thank you for your code.
A quick question. my dir name is been called from a database <%=(Recseesee.Fields.Item("imagepku").Value)%>
my directory i want deleted is inside "Uploadimages"
you folderpath = Server.MapPath("..\Uploadimages") 'change to the name the uploads root folder.
When I use your code at present it deletes the "Uploadimages" folder which is something i dont want. how can I add the name the uploads root folder when my value is dynamic.
I have tried
you folderpath = Server.MapPath("..\Uploadimages") & (Recseesee.Fields.Item("imagepku").Value)
only to get an error.
regards
k
You must me logged in to write a comment.