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)

link|improve this question
feedback

4 Answers

up vote 10 down vote accepted

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 MSWORD edit this file. Do a global replace on Newline normally ^p in MSWORD. Replace it with "space/Y^pdelspace". This will change

File1.bin
File20.bin
File21.bin

TO

File1.bin /Y
del File20.bin /Y
del File21.bin /Y
del

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

Run the batch command.

link|improve this answer
Apart from the /Y switch, which apparently doesn't work in win7 del command, this worked quite well .. thanks – Avishking Nov 9 '11 at 19:14
2  
That's probably supposed to be /f for "force delete read-only files" instead of /y. – afrazier Nov 9 '11 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 Nov 10 '11 at 7:09
feedback

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
link|improve this answer
This actually deleted the file list instead of the files themselves ... i had to create the list again :| – Avishking Nov 9 '11 at 19:11
2  
My deepest apologies. I forgot the /f flag. – William Jackson Nov 9 '11 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 Nov 9 '11 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. – BlueRaja Nov 9 '11 at 22:50
feedback

Using PowerShell:

Get-Content c:\path\to\list.txt | Remove-Item
link|improve this answer
Wow, that's way more readable than batch. – TheLQ Nov 15 '11 at 15:14
feedback

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.