Results 1 to 3 of 3
  1. #1
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,585
    Thanks
    146
    Thanked 7 Times in 7 Posts

    Macro Delete files in a folder based on text in Col C

    I have code to delete csv files in a folder called C:\data Analysis

    The files to be deleted in this folder in based in text contained in Col C for eg if filed is called BR1 Period 4 Sales.xlsx , I will have *period 4* in Col C and all files in C:\data analysis containing "period 4" are to be deleted

    I have attached my workbook, containing my code as well as some source files


    It would be appreciated if someone could assist me
    Attached Files Attached Files

  2. #2
    Super Moderator rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,446
    Thanks
    3
    Thanked 261 Times in 239 Posts
    I'd just call Del in DOS for that:

    Code:
    Sub Delete_Files()
        Dim rw As Long
        For rw = 2 To Cells(Rows.Count, "C").End(xlUp).Row
            Shell "cmd /k Del """ & Cells(2, "A").Value & "\" & Cells(rw, "C").Value, vbHide
        Next rw
    End Sub
    Regards,
    Rory

  3. #3
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,585
    Thanks
    146
    Thanked 7 Times in 7 Posts
    Thanks for the help, Rory

Posting Permissions

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