Is there an API or way to perform a DeleteTree easily?
Printable View
Is there an API or way to perform a DeleteTree easily?
Well - what is a deletetree ??Quote:
Originally posted by Mc Brain
Is there an API or way to perform a DeleteTree easily?
It's an old command (DelTree) of DOS that deletes all the files and folder on a specific folder (and on its children).
I think the FilesystemObject has a deleteFolder method that does that, doesnt it?Quote:
Originally posted by Mc Brain
It's an old command (DelTree) of DOS that deletes all the files and folder on a specific folder (and on its children).
You could use FileSystemObject's DeleteFolder property ...Quote:
Originally posted by Mc Brain
It's an old command (DelTree) of DOS that deletes all the files and folder on a specific folder (and on its children).
Thanks... I was looking for an API really. I'm not fond of the FSO.
Me neither .. let me see if i can find you some API ...Quote:
Originally posted by Mc Brain
Thanks... I was looking for an API really. I'm not fond of the FSO.
You can write a recursive loop to delete all files using DeleteFile API and then use RemoveDirectory to remove folders. Its easy.
you can always shell deltree :D :D :DQuote:
Originally posted by Mc Brain
Thanks... I was looking for an API really. I'm not fond of the FSO.
Give this a try.VB Code:
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 fAborted As Boolean hNameMaps As Long sProgress As String End Type Private Const FO_DELETE = &H3 Private Const FOF_ALLOWUNDO = &H40 Private Const FOF_NOCONFIRMATION = &H10 Public Sub DeleteFolder(ByVal strPath As String, _ Optional blnToRecycleBin As Boolean = True, _ Optional blnConfirm As Boolean = True) '''''''''''''''''''''''''''''''''''''''''''''''' 'Parameters 'strPath - The folder path 'blnToRecycleBin - True sends the file to the ' Recycle Bin. False deletes the file without ' sending it to the Recyle Bin. 'blnConfirm - True pops up a dialog to confirm ' delete. False deletes silently. ' ' EXAMPLES: '' Send folder to Recycle bin with confirmation ' DeleteFolder "c:\test folder" ' '' Send folder to Recycle bin without confirmation ' DeleteFolder "c:\test folder", , False ' '' Deletes folder by passing Recycle Bin with confirmation '' DeleteFolder "c:\test folder", False ' '' Deletes folder by passing Recycle Bin with confirmation '' DeleteFolder "c:\test folder", False, False ''''''''''''''''''''''''''''''''''''''''''''''' Dim FileOp As SHFILEOPSTRUCT Dim lngFlag As Long If blnToRecycleBin Then lngFlag = FOF_ALLOWUNDO End If If blnConfirm = False Then lngFlag = lngFlag + FOF_NOCONFIRMATION End If With FileOp .pFrom = strPath & vbNullChar .wFunc = FO_DELETE .fFlags = lngFlag End With SHFileOperation FileOp End Sub
Great, MarkT! It worked! Thanks a lot.Quote:
Originally posted by MarkT
Give this a try.VB Code:
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 fAborted As Boolean hNameMaps As Long sProgress As String End Type Private Const FO_DELETE = &H3 Private Const FOF_ALLOWUNDO = &H40 Private Const FOF_NOCONFIRMATION = &H10 Public Sub DeleteFolder(ByVal strPath As String, _ Optional blnToRecycleBin As Boolean = True, _ Optional blnConfirm As Boolean = True) '''''''''''''''''''''''''''''''''''''''''''''''' 'Parameters 'strPath - The folder path 'blnToRecycleBin - True sends the file to the ' Recycle Bin. False deletes the file without ' sending it to the Recyle Bin. 'blnConfirm - True pops up a dialog to confirm ' delete. False deletes silently. ' ' EXAMPLES: '' Send folder to Recycle bin with confirmation ' DeleteFolder "c:\test folder" ' '' Send folder to Recycle bin without confirmation ' DeleteFolder "c:\test folder", , False ' '' Deletes folder by passing Recycle Bin with confirmation '' DeleteFolder "c:\test folder", False ' '' Deletes folder by passing Recycle Bin with confirmation '' DeleteFolder "c:\test folder", False, False ''''''''''''''''''''''''''''''''''''''''''''''' Dim FileOp As SHFILEOPSTRUCT Dim lngFlag As Long If blnToRecycleBin Then lngFlag = FOF_ALLOWUNDO End If If blnConfirm = False Then lngFlag = lngFlag + FOF_NOCONFIRMATION End If With FileOp .pFrom = strPath & vbNullChar .wFunc = FO_DELETE .fFlags = lngFlag End With SHFileOperation FileOp End Sub
FINALLY!!!!!!
I been searching the forum for the past 4 hours, and found a similar approach to this one 2 hours ago, but i still needed to know how to use it without it popping the windows confirmation msg!!!!
THANK U (yes i know this thread is 3 years old, and no, this is not an edit :D )!!!!
VB Code:
'' Send folder to Recycle bin without confirmation ' DeleteFolder "c:\test folder", , False
:confused: :confused:Quote:
Originally Posted by cssriraman
I wasnt asking how to do it, i was just saying that this thread pointed out to me how to use the FOF_NOCONFIRMATION flag, that's all !!!
But thx anyways :rolleyes: ....
Ok. No problemo.
Ok... this thread is now 3.5 years old and just saved my bacon!!!
Thanks!!!!!
I was having a problem with the FSO.DeleteFolder method... it refused to cooporate...
Doing a forum search does pay off.
man, preach'n to the choir, brah... preach'n to the choir.
I am active at www.corvetteforum.com... and that is always one of my first recommendations. However, 98% are not IT pros and they don't think of using the search - or don't have a clue how it works.