简体   繁体   中英

Batch - Find string in text file and delete full line

I use the script from this Thread accepted answer from Mofi . The script copy folders and store them in text file to exclude once copied folders on next run.

Sometimes I have folders called [incomplete]-different.names and I do not want to copy this folders. I want that all folders with the string [incomplete]- and the name behind are skipped or are not even written in the text file %CurrentList% for further processing.

These are my previous attempts but so far I could not get up and running with the script from the top. Help would be nice, and thanks in advance.

Try 1:

for /f "delims=" [incomplete]-%%D in ("%CurrentList%") do ( set str=%%D set str=!str: =! set str=!str: %%D =! echo !str!

Try 2:

findstr /v /b /c:"[incomplete]-"%%D" "%CurrentList%" del "%%D"

You were really close with your second attempt.

If all you want is to delete lines in %CurrentList% that contain the string [incomplete]- , you can just direct the output of a findstr /v to a temp file and then overwrite CurrentList with that file.

findstr /v /c:"[incomplete]-" "%CurrentList%" >tmpList.txt
move /y tmpList.txt "%CurrentList%" >nul

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM