View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
pgarcia pgarcia is offline
external usenet poster
 
Posts: 304
Default Batch Delete VB code

Oh mannnnnnnnnnnnnn!!!!!!! That was awsom!!!
It worked like a charm. I've made a .bat once, but how does this one work?
What is
REM http://support.microsoft.com/default...EN-US;q272623& about?


Thanks

"Dave Peterson" wrote:

You could use VBA code, but I use this:

http://support.microsoft.com/default...EN-US;q272623&

In fact, I use this version of the .bat file:

==========

@echo off
REM http://support.microsoft.com/default...EN-US;q272623&
dir %1 /-p /b /o:gn /s "%temp%\Listing.txt"
start notepad "%temp%\Listing.txt"
exit

==========

I created this printdir.bat file in a nice safe folder.

Then I copied the file (using windows explorer) so that I could add a shortcut
to this .bat file to windows explorer rightclick menu.

In WinXP (Home), I could do:
Windows start button|Run
type:
Sendto

And my SendTo folder opens.
For me, it's:
C:\Documents and Settings\(username)\SendTo

Then I rightclicked on an empty spot in that folder and chose to paste shortcut.

Then I could rightclick on any folder in windows explorer and chose Send to,
then PrintDir.

Then I just copy|paste from notepad to what I need--either excel, MSWord, email,
.....








pgarcia wrote:

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


--

Dave Peterson