Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How about an alternative?
WHAT!?!? There's an alternative to using Excel!?!?! :-) 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ya, blasphemer!
"Charlotte E." wrote: How about an alternative? WHAT!?!? There's an alternative to using Excel!?!?! :-) 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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Using an Excel sheet for batch delete | Excel Worksheet Functions | |||
batch file call from a macro - how ? and required batch format | Excel Programming | |||
batch delete | Excel Discussion (Misc queries) | |||
Want to run a DOS batch file (.bat) From Excel VBA code | Excel Programming | |||
How to delete in batch the same color format letters in a cell | Excel Worksheet Functions |