无法删除文件夹 [英] Unable to delete folder
问题描述
我有以下代码来选择一个文件夹,然后将其删除。我保持
在删除实际文件夹的行上出现路径/文件错误。该行之前的
行删除文件夹中的文件,但是当程序试图删除
$ b中选择的文件夹时,我收到错误
消息$ b BrowseforFolderbyPath函数。
如何在
浏览文件夹对话框中删除用户选择的文件夹?
谢谢,
Anthony
************************ BEGIN CODE SNIPPET ****************************** *
ArchiveFolder = BrowseForFolderByPath(ProgramPath)
''检查用户是否点击了取消按钮。
如果ArchiveFolder = vbNullString那么
退出Sub
结束如果
''检查所选文件夹是否在程序文件夹下。
如果左(ArchiveFolder, Len(ArchiveFolder) - 5)< ProgramPath Or
(右(ArchiveFolder,4))类似于* [!0-9] *然后
MsgBox"这是一个无效的存档文件夹。 &安培; Chr $(13)& Chr $(13)
& _
档案馆位于 &安培;程序路径& " 。夹" &安培; Chr $
(13)& Chr $(13)& _
"请选择... &安培;程序路径& "文件夹。,
vbOKOnly + vbInformation,无效的存档文件夹。
退出子
结束如果
strDeleteQuestion = MsgBox(你真的想删除&
ArchiveFolder&" archive?, vbYesNo + vbQuestion,删除存档。
如果strDeleteQuestion = vbYes那么
''删除所选档案中的所有文件文件夹。
杀死ArchiveFolder& " \ * *" < ----------------
- 此行有效。
Delete_Destination = ArchiveFolder& " \" < ------这个
行失败。
RmDir Delete_Destination
MsgBox" The档案已成功删除。,vbOKOnly
+ VbInformation,成功!
结束如果
****************************结束代码SNIPPET
******** ************************************
这是我正在使用的函数用于BrowseforfolderbyPath:
公共函数BrowseForFolderByPath(sSelPath As String)As String
Dim BI as BROWSEINFO
Dim pidl As Long
Dim lpSelPath As Long
Dim spath As String * MAX_PATH
BI
.hOwner = Me.hwnd
.pidlRoot = 0
如果RestoreArchive = True那么
.lpszTitle =" Archives位于应用程序的文件夹下。 &
Chr $(13)& 你要恢复什么档案?
否则
.lpszTitle ="档案位于应用程序的文件夹下。 &
Chr $(13)& 你要删除什么档案?
结束如果
.lpfn = FARPROCl(AddressOf BrowseCallbackProcStr)
lpSelPath = LocalAlloc(LPTR,Len(sSelPath)+ 1)
CopyMemory ByVal lpSelPath,ByVal sSelPath,Len(sSelPath)+ 1
.lParam = lpSelPath
结束
pidl = SHBrowseForFolder(BI)
如果pidl那么
如果是SHGetPathFromIDList(pidl,spath)那么
BrowseForFolderByPath = Left $(spath,InStr(spath,vbNullChar) - 1)
结束如果
调用CoTaskMemFree(pidl)
结束如果
调用LocalFree(lpSelPath)
结束函数
公共函数IsWinNT()作为布尔值
#If Win32然后
昏暗的OSV作为OSVERSIONINFO
OSV.OSVSize = Len(OSV)
''API返回1如果成功通话
如果GetVersionEx(OSV)= 1那么
' 'PlatformId包含一个代表
''操作系统的值,所以如果它是VER_PLATFORM_WIN32_NT,
''返回true
IsWinNT = OSV .PlatformID = VER_PLATFORM_WIN32_NT
结束如果
#End如果
结束功能
>
-
通过AccessMonster.com发布的消息
http://www.accessmonster.com/Uwe/For...ccess/200705/1
(13)& Chr
(13)
& _
档案馆位于 &安培;程序路径& " 。夹" &安培; Chr
(13)&字符
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
BrowseforFolderbyPath 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 = BrowseForFolderByPath(ProgramPath)
''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(ArchiveFolder, Len(ArchiveFolder) - 5) <ProgramPath Or
(Right(ArchiveFolder, 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
strDeleteQuestion = MsgBox("Do you really want to delete the " &
ArchiveFolder & " archive?", vbYesNo + vbQuestion, "Delete Archive.")
If strDeleteQuestion = vbYes Then
''delete all files in the selected archive folder.
Kill ArchiveFolder & "\*.*" <----------------
- this line works.
Delete_Destination = ArchiveFolder & "\" <------ this
line fails.
RmDir Delete_Destination
MsgBox "The Archive has been successfully deleted.", vbOKOnly
+ VbInformation, "Success!"
End If
**************************** END CODE SNIPPET
********************************************
This is the function I''m using for the BrowseforfolderbyPath:
Public Function BrowseForFolderByPath(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(AddressOf BrowseCallbackProcStr)
lpSelPath = LocalAlloc(LPTR, Len(sSelPath) + 1)
CopyMemory ByVal lpSelPath, ByVal sSelPath, Len(sSelPath) + 1
.lParam = lpSelPath
End With
pidl = SHBrowseForFolder(BI)
If pidl Then
If SHGetPathFromIDList(pidl, spath) Then
BrowseForFolderByPath = Left$(spath, InStr(spath, vbNullChar) - 1)
End If
Call CoTaskMemFree(pidl)
End If
Call LocalFree(lpSelPath)
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(OSV) = 1 Then
''PlatformId contains a value representing
''the OS, so if it''s VER_PLATFORM_WIN32_NT,
''return true
IsWinNT = OSV.PlatformID = VER_PLATFORM_WIN32_NT
End If
#End If
End Function
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200705/1
(13) & Chr
(13)
& _
"Archives are located in the " & ProgramPath & " folder." & Chr
(13) & Chr
这篇关于无法删除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!