LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Batch Delete VB code

Do you know of a VB code that will give me a full list of files name
within a director and sub folder too and put it in column A?


I sent you one privately a couple of days ago.

Sub FindFilesONLY()
'change to suit
mypath = "c:\A_D\BoneyJames"
'=====
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = mypath
.SearchSubFolders = True 'False
.MatchTextExactly = False
.Filename = ".mp3" '*.mp3* did not work in 97
If .Execute(msoSortOrderDescending) 0 Then

MsgBox "There were " & .FoundFiles.Count & " file(s) found."

For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
Next i

End If

End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"pgarcia" wrote in message
...
Thanks, yes will I was thinking that it would pick up the extension .m4a.
You
are correct on that point. Is there a way to pick up the full path? I used
"Command Prompt" to get the name (C:\Documents and Settings\My
Documents\My
Music dir/sM4A.txt). It does give you all the information, but on
different
lines. Do you know of a VB code that will give me a full list of files
name
within a director and sub folder too and put it in column A?

Did I say thanks yet? Thank!

"Dave Peterson" wrote:

And I forgot to toggle my error checking:

with activesheet
for each mycell in .range("a2",.cells(.rows.count,"A").end(xlup)).cel ls
on error resume next
kill mycell.value
if err.number < 0 then
mycell.offset(0,1).value = "Error!"
err.clear
else
mycell.offset(0,1).value = "Deleted"
end if
on error goto 0 '<-- added
next mycell
end with

Dave Peterson wrote:

Aren't you afraid that you'll have the same filename used in different
subfolders?

And if you delete by filename alone, you could be deleting the wrong
file(s).

I think I'd create a list in excel that includes the path. Then just
use

with activesheet
for each mycell in
.range("a2",.cells(.rows.count,"A").end(xlup)).cel ls
on error resume next
kill mycell.value
if err.number < 0 then
mycell.offset(0,1).value = "Error!"
err.clear
else
mycell.offset(0,1).value = "Deleted"
end if
next mycell
end with

=======
But to answer your original question, no, your code won't look at
subfolders.

pgarcia wrote:

Thanks, but the problem is, I had to stop my conver of .m4a to .mp3,
so I
have list of .m4a that need to be deleted, but also from that list is
.m4a
that have not been conver yet. I need to keep those and conver at a
later
time. The conver takes a few days as I have round 35Gb of music.

"Dave Peterson" wrote:

How about an alternative?

Open windows explorer.
Traverse to your My Music folder
Search for *.m4a
Include subfolders in your search
after the search is finished
click on the results window (to the right)
Ctrl-a
to select all those files.
hit the delete key on the keyboard.

pgarcia wrote:

I found the following code. Does any one know if this will run
through the
sub folders? I have around 200 folder and need to delete .m4a
files. Thanks

Sub test()
MyPath = "C:\Documents and Settings\My Documents\My Music"
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

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using an Excel sheet for batch delete Colin Hayes Excel Worksheet Functions 18 September 23rd 08 04:38 PM
batch file call from a macro - how ? and required batch format VB-rookie Excel Programming 4 September 6th 08 12:52 AM
batch delete jason2444 Excel Discussion (Misc queries) 1 September 21st 06 04:01 AM
Want to run a DOS batch file (.bat) From Excel VBA code Cazayoux Excel Programming 1 July 31st 06 10:45 PM
How to delete in batch the same color format letters in a cell yang xin Excel Worksheet Functions 1 February 5th 06 04:42 AM


All times are GMT +1. The time now is 10:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"