i have a folder with 2K+ files in it, i need to delete around 200, i have a txt file with all the file names i need removed ordered in a list, how do i remove the specific files from the folder using the list? (OS is windows 7)

6 Answers 6


Simple way is copy the txt file to a file called mydel.bat in the directory of the files to delete. Using an editor like Microsoft Word edit this file. Do a global replace on Newline normally ^p in Word. Replace it with space/f^pdelspace. This will change


to (with /f for "force delete read-only files"):

File1.bin /f
del File20.bin /f
del File21.bin /f

Edit the fist line to add the del space and delete the last line.

Run the batch command.

  • Apart from the /Y switch, which apparently doesn't work in win7 del command, this worked quite well .. thanks
    – Avishking
    Commented Nov 9, 2011 at 19:14
  • 3
    That's probably supposed to be /f for "force delete read-only files" instead of /y.
    – afrazier
    Commented Nov 9, 2011 at 19:55
  • Correct afrazier. I was mixing up the /Y which works with XCOPY and one or two other DOS programs to 'Suppress prompting to confirm action'
    – kingchris
    Commented Nov 10, 2011 at 7:09
  • In editors who know how to do find/replace with regex, such as Notepad++, you would need to replace "^" with "del " and "$" with " /f", where ^ represents the beginning of each row and $ - the end. Commented Jan 10, 2018 at 19:41
  • or via a Spreadsheet / Excel filenames in 1st column then ="del "&A1 in the 2nd Ctrl+Shift+End to select to last row > Ctrl+D to "fill down" "Copy & Paste" new column into +new sheet > "123 Values" > "File > Save As..." so just deleted 3672 duplicate files using the .txt file generated with free "CCcleaner" tool. Yielding 71GB of space.
    – social
    Commented Oct 16, 2023 at 4:10

Type this on the command line, substituting your file for files_to_delete.txt:

for /f %i in (files_to_delete.txt) do del %i

A version of this suitable to include in .cmd files (double %%) and able to deal with spaces in file names:

for /f "delims=" %%f in (files_to_delete.txt) do del "%%f"
  • 1
    This actually deleted the file list instead of the files themselves ... i had to create the list again :|
    – Avishking
    Commented Nov 9, 2011 at 19:11
  • 4
    My deepest apologies. I forgot the /f flag. Commented Nov 9, 2011 at 19:40
  • That's pretty nifty, I didn't know the command line supported loops like that. Care to write a blog post for the SU blog about this and other intricacies of the command line?
    – Ivo Flipse
    Commented Nov 9, 2011 at 22:11
  • 1
    @Ivo: You might want to take a look at computerhope.com/batch.htm or superuser.com/questions/tagged/batch to learn more. Like Unix, much of what can be done in scripts (batch files) can also be done directly from the command-line. Commented Nov 9, 2011 at 22:50
  • I created a bat file and copied the 2nd example: result: the files_to_delete.txt is still removed. (even with the /f flag)
    – bvdb
    Commented Jul 27, 2016 at 7:29

Using PowerShell:

Get-Content c:\path\to\list.txt | Remove-Item
  • 2
    Wow, that's way more readable than batch.
    – TheLQ
    Commented Nov 15, 2011 at 15:14
  • 2
    For future readers... I had to change the pipe operator to a > to make this work. I.e. Get-Content c:\path\to\list.txt > Remove-Item ... I had full UNC paths in my list.txt. Hope this helps.
    – NateJ
    Commented Apr 11, 2017 at 21:43
  • @NateJ I tried using the > and it just created a file for me, instead of deleting things.
    – Brian J
    Commented Nov 30, 2017 at 14:47
  • @BrianJ hmm, I’ll have to check back on what I did.. good catch.
    – NateJ
    Commented Nov 30, 2017 at 19:59

First method works after some changes:

  1. open Notepad
  2. copy all file names with extension which need to be deleted after adding del at the beginning like

    del File1.bin
    del File20.bin
    del File21.bin
  3. save the file as xyz.bat in the same folder

  4. run the file
  • 3
    ...the text file in the question has about 200 file names in it. Why add del manually like you're proposing, while solutions were already posted to automate it? As an aside: any sane editor would have some support for searching and replace including line endings (or line starts, using regular expressions), macros, or for block or column mode editing (often initiated by holding down Option or Alt and then selecting a block, after which one can just type on multiple lines at once).
    – Arjan
    Commented May 21, 2015 at 6:56

I imagine it can be done with powershell.

Knowing Perl, I tend to use it for this sort of thing

perl -l -n -e "unlink" filenames.txt

"for /f", as shown in many posts above and/or using a batch (.bat) script of any kind, are the best methods for large file deletion processing, however, if you have a smaller list (or you want a really long command), you can use a space delimited list with the del command directly from a command prompt by doing something like this:

C:\myfolder> del File1.bin File20.bin File21.bin

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .