Results 1 to 18 of 18

Thread: DeleteTree

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    DeleteTree

    Is there an API or way to perform a DeleteTree easily?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: DeleteTree

    Originally posted by Mc Brain
    Is there an API or way to perform a DeleteTree easily?
    Well - what is a deletetree ??

  3. #3

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    It's an old command (DelTree) of DOS that deletes all the files and folder on a specific folder (and on its children).
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    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).
    I think the FilesystemObject has a deleteFolder method that does that, doesnt it?

  5. #5
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    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 ...

  6. #6

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Thanks... I was looking for an API really. I'm not fond of the FSO.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by Mc Brain
    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 ...

  8. #8
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    You can write a recursive loop to delete all files using DeleteFile API and then use RemoveDirectory to remove folders. Its easy.

  9. #9
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by Mc Brain
    Thanks... I was looking for an API really. I'm not fond of the FSO.
    you can always shell deltree

  10. #10
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Give this a try.
    VB Code:
    1. Private Declare Function SHFileOperation _
    2.  Lib "shell32.dll" Alias "SHFileOperationA" ( _
    3.  lpFileOp As SHFILEOPSTRUCT) As Long
    4.  
    5. Private Type SHFILEOPSTRUCT
    6.     hwnd As Long
    7.     wFunc As Long
    8.     pFrom As String
    9.     pTo As String
    10.     fFlags As Integer
    11.     fAborted As Boolean
    12.     hNameMaps As Long
    13.     sProgress As String
    14. End Type
    15.  
    16. Private Const FO_DELETE = &H3
    17. Private Const FOF_ALLOWUNDO = &H40
    18. Private Const FOF_NOCONFIRMATION = &H10
    19.  
    20. Public Sub DeleteFolder(ByVal strPath As String, _
    21.     Optional blnToRecycleBin As Boolean = True, _
    22.     Optional blnConfirm As Boolean = True)
    23. ''''''''''''''''''''''''''''''''''''''''''''''''
    24. 'Parameters
    25. 'strPath - The folder path
    26. 'blnToRecycleBin - True sends the file to the
    27. '   Recycle Bin. False deletes the file without
    28. '   sending it to the Recyle Bin.
    29. 'blnConfirm - True pops up a dialog to confirm
    30. '   delete. False deletes silently.
    31. '
    32. '   EXAMPLES:
    33. ''   Send folder to Recycle bin with confirmation
    34. '    DeleteFolder "c:\test folder"
    35. '
    36. ''   Send folder to Recycle bin without confirmation
    37. '    DeleteFolder "c:\test folder", , False
    38. '
    39. ''   Deletes folder by passing Recycle Bin with confirmation
    40. ''    DeleteFolder "c:\test folder", False
    41. '
    42. ''   Deletes folder by passing Recycle Bin with confirmation
    43. ''    DeleteFolder "c:\test folder", False, False
    44. '''''''''''''''''''''''''''''''''''''''''''''''
    45. Dim FileOp As SHFILEOPSTRUCT
    46. Dim lngFlag As Long
    47.  
    48.     If blnToRecycleBin Then
    49.         lngFlag = FOF_ALLOWUNDO
    50.     End If
    51.    
    52.     If blnConfirm = False Then
    53.         lngFlag = lngFlag + FOF_NOCONFIRMATION
    54.     End If
    55.    
    56.     With FileOp
    57.         .pFrom = strPath & vbNullChar
    58.         .wFunc = FO_DELETE
    59.         .fFlags = lngFlag
    60.     End With
    61.    
    62.     SHFileOperation FileOp
    63.    
    64. End Sub

  11. #11

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by MarkT
    Give this a try.
    VB Code:
    1. Private Declare Function SHFileOperation _
    2.  Lib "shell32.dll" Alias "SHFileOperationA" ( _
    3.  lpFileOp As SHFILEOPSTRUCT) As Long
    4.  
    5. Private Type SHFILEOPSTRUCT
    6.     hwnd As Long
    7.     wFunc As Long
    8.     pFrom As String
    9.     pTo As String
    10.     fFlags As Integer
    11.     fAborted As Boolean
    12.     hNameMaps As Long
    13.     sProgress As String
    14. End Type
    15.  
    16. Private Const FO_DELETE = &H3
    17. Private Const FOF_ALLOWUNDO = &H40
    18. Private Const FOF_NOCONFIRMATION = &H10
    19.  
    20. Public Sub DeleteFolder(ByVal strPath As String, _
    21.     Optional blnToRecycleBin As Boolean = True, _
    22.     Optional blnConfirm As Boolean = True)
    23. ''''''''''''''''''''''''''''''''''''''''''''''''
    24. 'Parameters
    25. 'strPath - The folder path
    26. 'blnToRecycleBin - True sends the file to the
    27. '   Recycle Bin. False deletes the file without
    28. '   sending it to the Recyle Bin.
    29. 'blnConfirm - True pops up a dialog to confirm
    30. '   delete. False deletes silently.
    31. '
    32. '   EXAMPLES:
    33. ''   Send folder to Recycle bin with confirmation
    34. '    DeleteFolder "c:\test folder"
    35. '
    36. ''   Send folder to Recycle bin without confirmation
    37. '    DeleteFolder "c:\test folder", , False
    38. '
    39. ''   Deletes folder by passing Recycle Bin with confirmation
    40. ''    DeleteFolder "c:\test folder", False
    41. '
    42. ''   Deletes folder by passing Recycle Bin with confirmation
    43. ''    DeleteFolder "c:\test folder", False, False
    44. '''''''''''''''''''''''''''''''''''''''''''''''
    45. Dim FileOp As SHFILEOPSTRUCT
    46. Dim lngFlag As Long
    47.  
    48.     If blnToRecycleBin Then
    49.         lngFlag = FOF_ALLOWUNDO
    50.     End If
    51.    
    52.     If blnConfirm = False Then
    53.         lngFlag = lngFlag + FOF_NOCONFIRMATION
    54.     End If
    55.    
    56.     With FileOp
    57.         .pFrom = strPath & vbNullChar
    58.         .wFunc = FO_DELETE
    59.         .fFlags = lngFlag
    60.     End With
    61.    
    62.     SHFileOperation FileOp
    63.    
    64. End Sub
    Great, MarkT! It worked! Thanks a lot.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  12. #12
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Exclamation Re: DeleteTree

    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 )!!!!
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  13. #13
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: DeleteTree

    VB Code:
    1. ''   Send folder to Recycle bin without confirmation
    2. '    DeleteFolder "c:\test folder", , False
    CS

  14. #14
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: DeleteTree

    Quote Originally Posted by cssriraman
    VB Code:
    1. ''   Send folder to Recycle bin without confirmation
    2. '    DeleteFolder "c:\test folder", , False


    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 ....
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  15. #15
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: DeleteTree

    Ok. No problemo.
    CS

  16. #16
    Lively Member
    Join Date
    Nov 2006
    Location
    San Pedro, CA
    Posts
    104

    Re: DeleteTree

    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...

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DeleteTree

    Doing a forum search does pay off.

  18. #18
    Lively Member
    Join Date
    Nov 2006
    Location
    San Pedro, CA
    Posts
    104

    Re: DeleteTree

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width