VB删除目录里面的文件夹和文件
已知C:\QQ\AD有些文件和文件夹,想用VB删除,用了很多方法都不行````右键删除是可以的..VB我试了RMDIRSHELLCMDRDCMDRMDIR都不行`````...
已知C:\QQ\AD 有些文件和文件夹,想用VB删除,用了很多方法都不行````右键删除是可以的..
VB我试了 RMDIR SHELL CMD RD CMD RMDIR 都不行`````
问题是,,那个文件夹里面有很多不知道什么名的文件虽然可KILL *.* 但是还有很多个文件夹在里面,而且那些文件夹里面又有文件..
就比如说,我要删除QQ整个目录及里面的文件夹和文件````` 展开
VB我试了 RMDIR SHELL CMD RD CMD RMDIR 都不行`````
问题是,,那个文件夹里面有很多不知道什么名的文件虽然可KILL *.* 但是还有很多个文件夹在里面,而且那些文件夹里面又有文件..
就比如说,我要删除QQ整个目录及里面的文件夹和文件````` 展开
1个回答
展开全部
KILL 删除文件
RmDir path 删除目录或文件夹
如果没有指定驱动器,则RmDir会在当前驱动器上删除目录或文件夹。如果想要使用RmDir删除一个含有文件的目录或文件夹,则会发生错误。只有用Kill语句删除所有文件后,才能用来RmDir删除目录或文件夹
问题补充:照你的意思 看来一句话完成你想要的命令是不行的。必须先列举里面的的文件夹 然后删除里面的文件在删除文件才可以,不过这样比较麻烦,我刚从别处摘抄了一段代码 是强行删除带有文件的目录,你自己在套用里面的函数就可以了,希望对你有帮助。。
'VB强行删除目录或(VB强行删除文件)模块源码
Public Enum FO_Operation
FO_MOVE = 1
FO_COPY = 2
FO_DELETE = 3
FO_RENAME = 4
End Enum
Public Enum FOFlags
FOF_MULTIDESTFILES = &H1 'Destination specifies multiple files
FOF_SILENT = &H4 'Don't display progress dialog
FOF_RENAMEONCOLLISION = &H8 'Rename if destination already exists
FOF_NOCONFIRMATION = &H10 'Don't prompt user
FOF_WANTMAPPINGHANDLE = &H20 'Fill in hNameMappings member
FOF_ALLOWUNDO = &H40 'Store undo information if possible
FOF_FILESONLY = &H80 'On *.*, don't copy directories
FOF_SIMPLEPROGRESS = &H100 'Don't show name of each file
FOF_NOCONFIRMMKDIR = &H200 'Don't confirm making any needed dirs
End Enum
Public Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long ' only used if FOF_SIMPLEPROGRESS
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private op As SHFILEOPSTRUCT
Public Sub DeleteFolder(sDeleteFolder As String, Optional Interface As Boolean = False)
SetAttr sDeleteFolder, vbNormal
With op
.wFunc = FO_DELETE
.pFrom = sDeleteFolder
.fFlags = IIf(Interface = False, FOF_NOCONFIRMATION, FOF_NOCONFIRMATION And FOF_SILENT)
End With
SHFileOperation op
End Sub
'假如你要删除的目录是:"c:\temp",无论它有多少子目录,有多少文件,一样被删除,前提是目录已经存在。
RmDir path 删除目录或文件夹
如果没有指定驱动器,则RmDir会在当前驱动器上删除目录或文件夹。如果想要使用RmDir删除一个含有文件的目录或文件夹,则会发生错误。只有用Kill语句删除所有文件后,才能用来RmDir删除目录或文件夹
问题补充:照你的意思 看来一句话完成你想要的命令是不行的。必须先列举里面的的文件夹 然后删除里面的文件在删除文件才可以,不过这样比较麻烦,我刚从别处摘抄了一段代码 是强行删除带有文件的目录,你自己在套用里面的函数就可以了,希望对你有帮助。。
'VB强行删除目录或(VB强行删除文件)模块源码
Public Enum FO_Operation
FO_MOVE = 1
FO_COPY = 2
FO_DELETE = 3
FO_RENAME = 4
End Enum
Public Enum FOFlags
FOF_MULTIDESTFILES = &H1 'Destination specifies multiple files
FOF_SILENT = &H4 'Don't display progress dialog
FOF_RENAMEONCOLLISION = &H8 'Rename if destination already exists
FOF_NOCONFIRMATION = &H10 'Don't prompt user
FOF_WANTMAPPINGHANDLE = &H20 'Fill in hNameMappings member
FOF_ALLOWUNDO = &H40 'Store undo information if possible
FOF_FILESONLY = &H80 'On *.*, don't copy directories
FOF_SIMPLEPROGRESS = &H100 'Don't show name of each file
FOF_NOCONFIRMMKDIR = &H200 'Don't confirm making any needed dirs
End Enum
Public Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long ' only used if FOF_SIMPLEPROGRESS
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private op As SHFILEOPSTRUCT
Public Sub DeleteFolder(sDeleteFolder As String, Optional Interface As Boolean = False)
SetAttr sDeleteFolder, vbNormal
With op
.wFunc = FO_DELETE
.pFrom = sDeleteFolder
.fFlags = IIf(Interface = False, FOF_NOCONFIRMATION, FOF_NOCONFIRMATION And FOF_SILENT)
End With
SHFileOperation op
End Sub
'假如你要删除的目录是:"c:\temp",无论它有多少子目录,有多少文件,一样被删除,前提是目录已经存在。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询