View Single Post
  #19   Report Post  
Posted to microsoft.public.excel.worksheet.functions
pgarcia pgarcia is offline
external usenet poster
 
Posts: 304
Default Using an Excel sheet for batch delete

Does this work if you have the file extention listed in the file name or
spaces in the name? I need to delete .aac & .wma files. Also, can you run
through sub folders? Meaning, I have 200 folders (albums) and I already have
the list, I need to delete the files within the folders.

Directory is: C:\Documents and Settings\My Documents\My Music
Sub Directory: C:\Documents and Settings\\My Documents\My Music\50 Cent
File name: 01 01 Track 1 Unknown Artist Unknown Album (4-24-2008 8-04-25
AM).wma

"Per Jessen" wrote:

Hi

Try this:

Sub test()
MyPath = "c:\temp\"
Set fs = CreateObject("Scripting.FileSystemObject")

LastRow = Range("A1").End(xlDown).Row

For r = 2 To LastRow
fs.DeleteFile MyPath & Cells(r, "A").Value
Cells(r, "A").ClearContents ' Remove file from list after deleting it
Next

End Sub

Best regards,
Per

"Colin Hayes" skrev i meddelelsen
...

HI All

I have an Excel worksheet with a list of file names in column A.

I'd like to use this list to look into a named directory (perhaps built in
to the routine , or entered via a popup) and delete files of the same name
in turn.

Once a file is deleted , then the routine would go back to Excel and look
up the next file name in the column for the next delete , and so on until
it reaches the end of the list.

Can someone help with this , please?

Grateful for any advice.



Best Wishes