Delete folders/files that are not listed in a textfile -
i need batch file read list of paths text file. if list not include path of subfolders/files in windows explorer, removed.
for example, in d:\test
contains:
hi <directory> bye <directory> hello.txt cya.txt checklist.txt
so in my checklist.txt
:(this list containing folders/files shouldn't deleted)
d:\test\hi d:\test\hello.txt d:\test\checklist.txt
as result, after running batch file, bye folder
, cya.txt
removed.
stack overflow not write-code-for-me site!
you should add code before ask, otherwise, question closed "unclear asking".
anyways here code.
@echo off setlocal enabledelayedexpansion /f %%g in (checklist.txt) ( set "str=%%~g !str!" ) /f %%g in ('dir /b ^| findstr /v /i "%str%"') ( echo del "%%~g" rem remove echo statement when shows correct result ) pause
loops through files in checklist.txt
, remove them unnecessary files. remove echo
whenever necessary.
Comments
Post a Comment