Hi,
I have the following code to select a folder and then delete it. I keep
getting a Path/File error on the line that deletes the actual folder. The
line before that line deletes the files in the folder but I get the error
message when the procedure attempts to delete the folder selected in the
BrowseforFolder byPath function.
How can I get it to delete the folder that the user has selected in the
Browse for Folder dialog?
Thanks,
Anthony
*************** ********* BEGIN CODE SNIPPET *************** ***************
ArchiveFolder = BrowseForFolder ByPath(ProgramP ath)
'check if user has clicked the Cancel button.
If ArchiveFolder = vbNullString Then
Exit Sub
End If
'check if the selected folder is under the program folder.
If Left(ArchiveFol der, Len(ArchiveFold er) - 5) <ProgramPath Or
(Right(ArchiveF older, 4)) Like "*[!0-9]*" Then
MsgBox "That is an invalid Archive folder." & Chr$(13) & Chr$(13)
& _
"Archives are located in the " & ProgramPath & " folder." & Chr$
(13) & Chr$(13) & _
"Please select an archive in the " & ProgramPath & " folder.",
vbOKOnly + vbInformation, "Invalid Archive Folder."
Exit Sub
End If
strDeleteQuesti on = MsgBox("Do you really want to delete the " &
ArchiveFolder & " archive?", vbYesNo + vbQuestion, "Delete Archive.")
If strDeleteQuesti on = vbYes Then
'delete all files in the selected archive folder.
Kill ArchiveFolder & "\*.*" <----------------
- this line works.
Delete_Destinat ion = ArchiveFolder & "\" <------ this
line fails.
RmDir Delete_Destinat ion
MsgBox "The Archive has been successfully deleted.", vbOKOnly
+ VbInformation, "Success!"
End If
*************** ************* END CODE SNIPPET
*************** *************** **************
This is the function I'm using for the Browseforfolder byPath:
Public Function BrowseForFolder ByPath(sSelPath As String) As String
Dim BI As BROWSEINFO
Dim pidl As Long
Dim lpSelPath As Long
Dim spath As String * MAX_PATH
With BI
.hOwner = Me.hwnd
.pidlRoot = 0
If RestoreArchive = True Then
.lpszTitle = "Archives are located under the application's folder." &
Chr$(13) & "What Archive do you want to Restore?"
Else
.lpszTitle = "Archives are located under the application's folder." &
Chr$(13) & "What Archive do you want to Delete?"
End If
.lpfn = FARPROCl(Addres sOf BrowseCallbackP rocStr)
lpSelPath = LocalAlloc(LPTR , Len(sSelPath) + 1)
CopyMemory ByVal lpSelPath, ByVal sSelPath, Len(sSelPath) + 1
.lParam = lpSelPath
End With
pidl = SHBrowseForFold er(BI)
If pidl Then
If SHGetPathFromID List(pidl, spath) Then
BrowseForFolder ByPath = Left$(spath, InStr(spath, vbNullChar) - 1)
End If
Call CoTaskMemFree(p idl)
End If
Call LocalFree(lpSel Path)
End Function
Public Function IsWinNT() As Boolean
#If Win32 Then
Dim OSV As OSVERSIONINFO
OSV.OSVSize = Len(OSV)
'API returns 1 if a successful call
If GetVersionEx(OS V) = 1 Then
'PlatformId contains a value representing
'the OS, so if it's VER_PLATFORM_WI N32_NT,
'return true
IsWinNT = OSV.PlatformID = VER_PLATFORM_WI N32_NT
End If
#End If
End Function
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200705/1