中国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-15 15:00
47,813 topics / 349,903 posts / today 1 new / 48,257 members
DOS疑难解答 & 问题讨论 (解答室) » 请问如何删除特定行的文件? Translated: How to delete files with specific lines?
Printable Version  1,955 / 5
Floor1 aceonly Posted 2010-12-21 16:12
新手上路 Posts 3 Credits 8
Check the specified folder. If a line in a TXT file inside it is "HHHHHHH", immediately delete that file. If "HHHHHHH" appears in other lines, it can be ignored. The following code doesn't seem to solve my problem. Who is willing to help take a look? Thanks

set old=d:\test
set SRT1=HHHHHHH

for /f "delims=" %%c in ('dir /b /s /a-d "%old%\*.txt"') do (
for /f "delims=" %%d in (%%c) do (
if *%%d*==*%STR1%* del %%c))
Floor2 aceonly Posted 2010-12-22 16:16
新手上路 Posts 3 Credits 8
Is there anyone to help take a look? Thanks.
Floor3 aceonly Posted 2010-12-22 17:22
新手上路 Posts 3 Credits 8
Is my question is too simple or not explained clearly?

Suppose there are many TXT files in a directory:

File A:
123
456
123456


File B:
123
888
88456

If a specific string 456 is given, then file A should be deleted because the second line is exactly 456. And file B does not need to be deleted because 456 is only part of its third line.

Can anyone help? Or give a hint, I'm very new to this...
Floor4 DOSroot Posted 2010-12-24 00:04
管理员 Posts 198 Credits 389
Check if you posted in the wrong place:
http://www.cn-dos.net/forum/viewthread.php?tid=46409
Floor5 HAT Posted 2010-12-26 16:14
版主 Posts 5,017 Credits 9,023
If you are using the DOS system, its for command does not support /f.
Floor6 DOSforever Posted 2010-12-26 21:55
金牌会员 Posts 2,239 Credits 4,639
To be precise, it's that the FOR command in COMMAND that comes with DOS doesn't support the /f parameter. But if you use 4DOS as the command interpreter, it does support it.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023