中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-06 18:16
48,039 topics / 350,124 posts / today 0 new / 48,252 members
DOS批处理 & 脚本技术(批处理室) » Ask: How to batch delete files based on the content of a TXT file?
Printable Version  1,648 / 3
Floor1 wjxsjd Posted 2007-11-30 08:09
初级用户 Posts 15 Credits 31
How to batch delete files based on the content of a TXT file? The TXT file contains the file names to be deleted.
Thank you in advance!
Floor2 fastslz Posted 2007-11-30 08:57
铂金会员 Posts 2,315 Credits 5,493 From 上海
```batch
for /f "delims=" %a in (*.txt) do echo del /y "%a"
```
Floor3 xiaoyunwang Posted 2007-11-30 09:15
高级用户 Posts 374 Credits 940 From 湖南张家界
Just copy strings.com to the same directory. The first line of text.txt should not be an empty line, and there can be empty lines later (which will be automatically filtered).
Mainly use the read function provided by strings to read line content and the linesize function to read the number of lines in the file.
Suppose the content of test.txt is:

x.exe
y.txt
z.com

The content of the del.bat file to be deleted is:
@echo off
rem Initialize the test.txt file
strings linesize=linesize test.txt
strings files=read test.txt,1
if %files%#==# goto end
strings linesize=add %linesize%,1
set number=0

rem Traverse each file in test.txt through a loop and delete
rem Control the number of loops with the number variable
:cycle
if %number%#==%linesize%# goto next
strings number=add %number%,1
strings files=read test.txt,%number%
if %files%#==# goto cycle
del %files% >NUL
goto cycle

:next
echo The files in the test.txt list have been deleted!

:end
rem Clear environment variables
for %%a in (linesize files number) do set %%a=
Floor4 wjxsjd Posted 2007-11-30 09:23
初级用户 Posts 15 Credits 31
Thanks, I understand.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023