Created
November 11, 2013 22:36
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image1.jpg | |
image2.jpg | |
file1.txt | |
file2.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The TXT file should be saved with BOM.