Results 1 to 6 of 6

Thread: file Deletion

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    India
    Posts
    56

    file Deletion

    Hi there ...

    I have a small prob in my code ...

    I have a folder name and a list of file extensions

    now I want to delete all the files with those particular extensions

    these files can also be in the subfolders of the pathfolder...

    how should I do it?

    Its urgent...

    Regards,

    Nahush

  2. #2

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I imagine one of the easier ways would be to use FSO, though not the most desirable sometimes...
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim fso As New FileSystemObject
    3.    
    4.     Call EnumDelete(fso.GetFolder("C:\"), "*.tmp")
    5.  
    6.     Set fso = Nothing
    7.    
    8. End Sub
    9.  
    10. Private Sub EnumDelete(Path As Folder, DeletePattern As String)
    11. Dim fld As Folder
    12.  
    13.     On Error Resume Next
    14.         Kill Path.Path & DeletePattern
    15.     On Error GoTo 0
    16.  
    17.     For Each fld In Path.SubFolders
    18.         Call EnumDelete(fld, DeletePattern)
    19.     Next
    20.    
    21. End Sub

    Add a reference to the Microsoft Scripting Runtime.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2004
    Location
    India
    Posts
    56

    Urgent

    hi there

    does kill also deletes all the those particular files from the

    sub directories also?

    my prob is those file s can be in sub folders of the foler...

    Nahush

  5. #5
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    You would have to loop through all sub folders killing the specified extension on its loop. Not sure how, but the idea would be to kill like:

    Folder
    ---File1
    ---File2
    ---Sub Folder
    ------File3
    ------Sub Folder
    ---------File4
    ---------File5

    etc, how about a look on Planet Source Code?

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Guff to that, just look a couple of posts up.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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