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?
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) & "\")
Set folderObject = Nothing
Set fso = Nothing