Re: Mass delete files and directories
- From: "Mike Williams" <mikea@xxxxxxxxxxxxxxxxx>
- Date: Mon, 5 May 2008 17:30:35 +0100
"Grand_Poobah" <yoohoo@xxxxxxxxxxxxxx> wrote in message news:O$TyIasrIHA.800@xxxxxxxxxxxxxxxxxxxxxxx
I know that RmDir will delete an empty directory, but, outside of finding the deepest sub-directory and deleting
all the files in it, then deleting the actual directory and
working my back up, is there another way to do this?
The SHFileOperation function in the Shell32 library will do it for you. Be very careful though if you set the FOF_NOCONFIRMATION flag, especially if you do not have the FOF_ALLOWUNDO flag set (move to Recycle Bin), as in the following example, or you'll just zap the directory without giving the user a chance to change his mind or to get it back. By the way, if you paste the declaration into your code using your VB API Viewer AddIn then you might get a "Can't Find EntryPoint" error (at least I did when I just tried it) because the declaration in Wind32API.txt appears to have a spurious leading space in . . . Alias " SHFileOperationA".
Mike
Private Declare Function SHFileOperation _
Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long
Private 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 String ' if FOF_SIMPLEPROGRESS
End Type
Private Const FOF_SIMPLEPROGRESS As Integer = &H100
Private Const FOF_NOCONFIRMATION As Integer = &H10
Private Const FOF_ALLOWUNDO As Integer = &H40 ' recycle bin
Private Const FOF_SILENT As Long = &H4
Private Const FO_DELETE As Long = &H3
Private Function DeleteDirectory(s1 As String) As Long
Dim SHFileOp As SHFILEOPSTRUCT
With SHFileOp
.wFunc = FO_DELETE
.pFrom = s1
.fFlags = FOF_SIMPLEPROGRESS Or _
FOF_NOCONFIRMATION Or _
FOF_SILENT
End With
DeleteDirectory = SHFileOperation(SHFileOp)
End Function
Private Sub Command1_Click()
Dim retVal As Long
retVal = DeleteDirectory("c:\temp\somedirectory")
End Sub
I have some old routines that did this,
but I find that they are way too slow.
A user may have as much as several gigs of files (this is a virtual simulator) in hundreds of sub-directories so this could take aeon's to complete the task. I've looked several places and am familiar woth API calls, but have found nothing that helps me much.
Using VB6, with SP6.
GP
.
- Follow-Ups:
- Re: Mass delete files and directories
- From: Grand_Poobah
- Re: Mass delete files and directories
- From: Grand_Poobah
- Re: Mass delete files and directories
- References:
- Mass delete files and directories
- From: Grand_Poobah
- Mass delete files and directories
- Prev by Date: the '#' character inside a string
- Next by Date: Re: Clipboard question
- Previous by thread: Re: Mass delete files and directories
- Next by thread: Re: Mass delete files and directories
- Index(es):
Relevant Pages
|
Loading