Reputation: 11
I am trying to create a batch file that will search through a 3.5 TB partition and remove all files with a partially matching file name.
Our file structure is set up as a 5 digit item number then a possibly very random suffix before the extension. For example:
54326.jpg
54326 5x6.jpg
54326 (OLD ART).jpg
This has occurred through endless neglect of adherence to naming conventions and now we are about to purge the system of allot of random data. To make the problem harder it is scattered between 4 drives and a total of roughly 300,000 folders.
I was able to find this code from another forum but instead of moving it to another folder i just want to delete ALL instances using the item number.
for /r %%x in (54326*.*) do move "%%x" "DESTINATION"
I need the code to delete all files (of various extensions) using the 5 digit partial name from all folders on a hard drive.
I am using excel to group the code together as this will be done to roughly 25,000 product numbers. I am going to be given a list of product numbers to delete from. this list can be turned into a .txt
file if the code can index that txt
file in order to get the names to make things more simple.
Upvotes: 1
Views: 5075
Reputation: 703
dir "your location"
del /s 54326*.*
This will delete files that starts with 54326 as in your examples and leave the folders, but also delete within subfolders. Here's a few options:
/P Give a Yes/No Prompt before deleting.
/F Ignore read-only setting and delete anyway (FORCE)
/S Delete from all Subfolders (DELTREE)
/Q Quiet mode, do not give a Yes/No Prompt before deleting.
If you have a .txt file with a complete list of files you want to delete, you can do something like this
for /f "delims=" %%f in (your_text_file.txt) do del /s "%%f"
Upvotes: 2