Skip to content

Instantly share code, notes, and snippets.

@etiennetremel
Created November 11, 2013 22:36
Show Gist options
  • Save etiennetremel/7421770 to your computer and use it in GitHub Desktop.
Save etiennetremel/7421770 to your computer and use it in GitHub Desktop.
Batch keep files from txt file list, delete others The batch file is asking you to enter the folder name which contain all the files to check, and the name of the file which contain the list of files to keep. Files.txt list files to keep (one per line)
@echo off
setlocal
set /p folder="Enter name of the folder where the files are: " %=%
set /p excludeFile="Enter txt file name where the list of files to keep are: " %=%
for /f "eol=: delims=" %%F in ('dir /b /a-d %folder% ^| findstr /vibg:%excludeFile%') do (
echo "Deleting file %folder%\%%F"
del "%folder%\%%F"
)
echo "Done."
pause
image1.jpg
image2.jpg
file1.txt
file2.pdf
@byhbt
Copy link

byhbt commented Aug 28, 2018

The TXT file should be saved with BOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment