DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Delete files listed in excel sheet  (Read 7,823 times)

KoenFugro

  • Participant
  • Joined in 2008
  • *
  • Posts: 26
Delete files listed in excel sheet
« on: February 03, 2009, 01:14 PM »
Hi there people on this forum,

We recently discovererd a huge amount of duplicate files in one of the projects we do.
This files are spreaded everywhere, so deleting them by hand is really a job I dont wan't to do hehe!

I have a file listing in excel of all the duplicate files.. there is one column in excel, with the complete path and filename for example s:\ebn scanning\sf\processed\ebn000011111.pdf

All the files listed in excel must be deleted from the hard drive.
I think there must be a easy way to do that with AHK?

Thanks in advance people!


moonwatcher

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 8
Re: Delete files listed in excel sheet
« Reply #1 on: February 03, 2009, 01:32 PM »
Let excel do the work for you:

(example macro)


Option Explicit

Sub deleteFiles()
    Dim row, col As Integer
   
    row = 1 'starting row
    col = 1 'column with filenames
   
    While Not IsEmpty(Cells(row, col))
        If Dir(Cells(row, col)) <> "" Then
            Kill (Cells(row, col))
            Cells(row, col + 1) = "deleted"
        Else
            Cells(row, col + 1) = "not found"
        End If
        row = row + 1
    Wend
   
End Sub


This macro will get the filename from the first column in the active sheet, starting with the first row until the first blank cell is reached. A status is written into the 2nd column.
« Last Edit: February 03, 2009, 01:51 PM by moonwatcher »

KoenFugro

  • Participant
  • Joined in 2008
  • *
  • Posts: 26
Re: Delete files listed in excel sheet
« Reply #2 on: February 03, 2009, 01:38 PM »
Is this an AHK script? Or is this a VBA script?
I am not good in programming, so maybe a stupid question haha..

Thank for the really quick reaction!

moonwatcher

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 8
Re: Delete files listed in excel sheet
« Reply #3 on: February 03, 2009, 01:49 PM »
There are no stupid questions, only stupid answers ;-)

It is a VBA macro:

1) open your excel worksheet
2) press ALT+F11 to start the VBA editor
3) Insert -> Module
4) Paste the code into the editor
5) Alter the code to fit your needs (e.g. starting row and/or column number)
6) press ALT+F11 to switch back to excel
7) press ALT+F8 to run a macro and select deleteFiles

(you can speedup execution if you place Application.Calculate = false before the While-Loop and a corresponding Application.Calculate = true before the end-sub command; this will prevent excel from repainting the worksheet everytime a file has been deleted)
« Last Edit: February 03, 2009, 02:08 PM by moonwatcher »

KoenFugro

  • Participant
  • Joined in 2008
  • *
  • Posts: 26
Re: Delete files listed in excel sheet
« Reply #4 on: February 03, 2009, 02:50 PM »
Thanks alot!
I tried it and it worked for me!


;D

Original address: https://www.donationcoder.com/forum/index.php?topic=16881.0