Delete spare files

November 26, 2010 at 07:21:13
Specs: Windows 7, Q9550 / 4 Gig
Hey!

I need you help once more. I want to make a batch the will check the files that here are in a folder. If it finds others files (perhaps with the same extension) than a list I'll assign then it has to delete them. E.G.

I want in Myfolder to have only:
myfile1
myfile2
myfile3

But If there are
myfile1
myfile2
myfile3
otherfile1
otherfile2
otherfile3
(...)

the script will delete all other files.

Thanks in advance!


See More: Delete spare files

Report •

#1
November 26, 2010 at 09:29:06
:: keep files in keeplist
:: keepsome.bat Sat 27-11-2010 0:05:59.64
@echo off & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (keeplist) do (
set %%a=k
)

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
if not defined %%a del %%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 26, 2010 at 13:26:21
Thanks a lot it works. I suppose that instead of del %%a I can have copy %%a if O want spare files to be copied in a folder so i can check before final deleting, don't I?

Report •

#3
November 26, 2010 at 14:48:03
Yes. Or MOVE.


=====================================
Life is too important to be taken seriously.

M2


Report •
Related Solutions


Ask Question