Question:
How do you batch delete all files with end of the filename in common?
Randy D
2008-10-28 15:32:46 UTC
For example, I have 500 files in a folder, all of the form:

XXXXabc.ext
XXXXdef.ext
XXXXghi.ext
(all same file extensions)

Is there any way I can batch delete all of the files with file names ending in abc (XXXXabc.ext)? When I search through and try to select them all manually, I always miss a few or accidentally delete other ones. Plus, there is just too many files to do that efficiently.
Four answers:
Aaron
2008-10-28 16:13:42 UTC
Using the search tool does work as described above.



If you would like to make a batch file simply paste this into a notepad document and save it as anything.bat

Then double click the file to execute the dos commands below:



@echo off

Set CurDir = "C:\Documents and Settings\Aaron\temp"

cd %CurDir%

for /f %%f in ('dir /b *abc.exe') do (set myfile=%%f)

del %myfile%

for /f %%f in ('dir /b *efg.exe') do (set myfile=%%f)

del %myfile%

exit



Of course you can add as many for /f lines as you wish.

The quote marks are used because the path includes spaces.



EDIT: Oh. wait it's not by extension. grep doesn't work in windows d'oh, let me kick this around a minute.



EDIT2: I've corrected the dos commands for a batch file you can call from a double click or even the task scheduler for unattended operation.



HTH - Good Luck,

-Aaron
2008-10-28 15:44:58 UTC
this is proabably not the quickest way, but will do what you need:



1.click on search under the start menu.

2. under the search options click on search for files and folders

3. in the text box which has the label "All or part of the file name" enter *.ext to find all .ext files or to find all abc.ext enter *abc.ext.

4. if you want to find all .ext files on your computer, click search and it should find all of them.

5. if not, select the "look in" dropdown box and click on browse. you can then navigate to the folder you want to search for the files.



6. select all of the results and then either send the files to the recycle bin or press shift and delete on your keyboard to permantly delete them.
coe
2016-11-07 12:08:54 UTC
HAHA! This screams "propose comedian tale" to me. humorous which you be attentive to sufficient that a batch record may well be a area of it, yet don't be attentive to the thank you to jot down it :) Secondly, with the working device up and working, it is going to be close to impossible to delete the itemizing. good success figuring it out. i'm hoping whoever you're doing this to catches you.
2008-10-29 20:17:25 UTC
@echo off

:home

cls

set /p fname=Enter name of filepath of files you wish to delete from:

if "%fname%"=="%fname%" goto next

:next

echo.

set /p filn=Enter last three letters of all files to be deleted:

if "%filn%"=="%filn%" goto next2

:next2

cd "%fname%"

del /f /q "*%filn%.ext"

cls

echo All files ending with %filn% were deleted from %fname%.

pause >nul

goto home


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...