返回列表 发帖

[文本处理] 批处理怎样批量删除nfo文件中的指定标签及内容?

有100个nfo文件,其中包含的一个A.nfo文件内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<movie>
  <title>笑傲江湖</title>
  <actor>
    <name>未知</name>
    <type>Actor</type>
  </actor>
  <tag>笑傲江湖</tag>
  <tag>笑傲江湖</tag>

  <genre>笑傲江湖</genre>
  <poster>https://xxx.com/aaa.jpg</poster>
  <cover>https://xxx.com/aaa.jpg</cover>
  <website>https://xxx.com/aaa.jpg</website>
</movie>
其他nfo文件都是相同格式
删除其中<tag></tag>和中间的"笑傲江湖",其中"笑傲江湖"可能是其他汉字,字母,数字,符号。
简单来说就是类似批量删除xml格式文件中的指定标签及内容。

本帖最后由 aloha20200628 于 2025-4-13 21:52 编辑

回复 1# cckkaa888

试试以下两个版本》删除当前目录下 *.nfo 文件中包含指定字符串 <tag> 的所有文本行,其结果文件存于当前目录,扩展名为 *.new,指定字符串在代码中可自定义...

版本一。
@echo off &for /f "delims=" %%F in ('dir /b/a-d *.nfo') do findstr /iv "<tag>" "%%F">"%%F.new"
pause&exit/bCOPY
版本二。
@echo off &for /f "delims=" %%F in ('dir /b/a-d *.nfo') do find /i /v "<tag>" "%%F"|more +2>"%%F.new"
pause&exit/bCOPY

TOP

回复 2# aloha20200628


    两个都可以,感谢大佬,大佬真

TOP

返回列表