Reputation: 44673
I am looking to write a batch file that will remove all files from a directory where there file name ends in a particular number.
Eg delete all files of type .js from a folder where the filename end in 1.1.1.0
Any tips as to how I may write such a batch file to achieve this?
How would it be different if I wanted to delete all of the files of type .js that didn't end in 1.1.1.0?
Upvotes: 0
Views: 13340
Reputation: 10859
So, it seems you could just do:
del *1.1.1.0.js
Or, you could write a batch file (tmp.bat) like this:
del *%1.js
And call it:
tmp.bat 1.1.1.0
But that seems like overkill?
Is there something I'm missing?
Or, I guess you might want something like:
del %1\*%2.js
Which you would call as:
tmp.bat folderName 1.1.1.0
You may also want to pass a '/F' flag to delete, to make sure it deletes readonly files...
If you wanted to do files in subdirectories as well, the batch file could look like this:
echo del /f /s %1\*%2.js
Again, where %1 is the folder name to start from and %2 is the number you want to delete...
To do everything BUT a given number, you could do something like this:
attrib +h *%1.js
del /q *
attrib -h *%1.js
To delete everything BUT a given number, from a given folder you could do this:
pushd %1
attrib +h *%2.js
del /q *
attrib -h *%2.js
popd
Where %1 is the folder and %2 is the number
Upvotes: 4
Reputation: 83
Just create a .bat file with the following:
del *1.1.1.0.js
and save it in your directory. Every time you run it, it will delete the files ending in 1.1.1.0.js
Upvotes: 0