Searching for files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sanka
    New Member
    • Sep 2007
    • 14

    Searching for files

    Hi

    I need the code that will look in a folder for all the files that have the same file extension and then to delete/remove all these files

    Thanks

    Sanka
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Although the FileSystemObjec t model is probably the better way to go, a very simple method is to use the old Dir() function, like so...

    Please be careful playing with this sample code. Since it deletes files, it could have serious consequences.

    [CODE=vb]Dim FileName As String
    Dim FolderName As String
    FolderName = "C:\Temp\"
    FileName = Dir(FolderName & "*.Txt") ' Get first matching file.
    Do While FileName <> ""
    Kill FolderName & FileName
    FileName = Dir() ' Get next matching file.
    Loop[/CODE]

    Comment

    Working...