Board logo

标题: [文本处理] [已解决]批处理怎样把当前目录下所有的ass文件的""替换成「」? [打印本页]

作者: 1139054012    时间: 2024-5-17 17:17     标题: [已解决]批处理怎样把当前目录下所有的ass文件的""替换成「」?

当前目录有多个ass文件,路径和文件名可能包含各种特殊符号,空格,【】「」/,.。等等

文件名
[DVDRIP][炎のらびりんす][720x480_X264_AAC][01][2D8A6DC1].ass
[DVDRIP][炎のらびりんす][720x480_X264_AAC][02][2D8A6DC1].ass

举例
文件内包含一个或多个""
  1. Dialogue: 0,0:08:32.36,0:08:34.67,*Default,NTP,0,0,0,,你说"怎么一回事"? 就是这么一回事啊
  2. Dialogue: 0,0:08:28.29,0:08:30.52,*Default,NTP,0,0,0,,你说要把"那个"要送给"那个人" 有没有搞错啊?
复制代码
怎样替换成「」格式
  1. Dialogue: 0,0:08:32.36,0:08:34.67,*Default,NTP,0,0,0,,你说「怎么一回事」? 就是这么一回事啊
  2. Dialogue: 0,0:08:28.29,0:08:30.52,*Default,NTP,0,0,0,,你说要把「那个」要送给「那个人」有没有搞错啊?
复制代码
保存新建「更改后」文件夹内
作者: 77七    时间: 2024-5-17 23:52

批处理替换这个我觉得有点困难,请把真实文件上传到网盘,看下文本行格式有无规律。
作者: 1139054012    时间: 2024-5-18 01:52

回复 2# 77七

文件压缩上传老失败,直接放下字幕完整代码
  1. [Script Info]
  2. ; Script generated by Aegisub 3.3.2
  3. ; http://www.aegisub.org/
  4. Title: 漫游字幕
  5. Original Script:
  6. Synch Point: 0
  7. ScriptType: v4.00+
  8. PlayResX: 640
  9. PlayResY: 480
  10. Timer: 100.0000
  11. [Aegisub Project Garbage]
  12. Active Line: 12
  13. [V4+ Styles]
  14. Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
  15. Style: Default,方正准圆_GBK,28,&H00FFFFFF,&H00000000,&H00000000,&H00000000,-1,0,0,0,100,100,1,0,1,1,0,2,10,10,10,1
  16. [Events]
  17. Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
  18. Dialogue: 0,0:00:32.90,0:00:34.10,*Default,NTP,0,0,0,,我们可等了很不耐烦呢
  19. Dialogue: 0,0:00:34.24,0:00:36.82,*Default,NTP,0,0,0,,今天我们要定你这条命了
  20. Dialogue: 0,0:01:16.36,0:01:17.56,*Default,NTP,0,0,0,,那个架势是...
  21. Dialogue: 0,0:01:18.56,0:01:21.14,*Default,NTP,0,0,0,,擎天一柱重突刺
  22. Dialogue: 0,0:01:22.91,0:01:24.83,*Default,NTP,0,0,0,,觉悟吧!
  23. Dialogue: 0,0:01:24.98,0:01:27.90,*Default,NTP,0,0,0,,救命啊
  24. Dialogue: 0,0:01:35.57,0:01:36.97,*Default,NTP,0,0,0,,好痛
  25. Dialogue: 0,0:02:27.79,0:02:34.27,*Default,NTP,0,0,0,,(炎之迷宫)
  26. Dialogue: 0,0:03:26.58,0:03:31.35,*Default,NTP,0,0,0,,(是武士道迷宫?\N还是爱的迷宫?)
  27. Dialogue: 0,0:03:37.01,0:03:38.97,*Default,NTP,0,0,0,,小夏**~
  28. Dialogue: 0,0:03:39.25,0:03:41.84,*Default,NTP,0,0,0,,请等我一下~
  29. Dialogue: 0,0:03:41.85,0:03:42.49,*Default,NTP,0,0,0,,小霞?
  30. Dialogue: 0,0:03:45.77,0:03:47.42,*Default,NTP,0,0,0,,既然那么辛苦的话
  31. Dialogue: 0,0:03:47.51,0:03:49.09,*Default,NTP,0,0,0,,大可不必跟我来啊
  32. Dialogue: 0,0:03:49.15,0:03:50.53,*Default,NTP,0,0,0,,您怎么能这么说呢?
  33. Dialogue: 0,0:03:50.62,0:03:52.00,*Default,NTP,0,0,0,,能像现在这样待在小夏**身边
  34. Dialogue: 0,0:03:52.03,0:03:54.80,*Default,NTP,0,0,0,,并时常替小夏**服务或保护小夏**
  35. Dialogue: 0,0:03:54.84,0:03:56.59,*Default,NTP,0,0,0,,可是小霞我的责任
  36. Dialogue: 0,0:03:57.06,0:03:59.29,*Default,NTP,0,0,0,,如果小夏**有个什么万一的话
  37. Dialogue: 0,0:04:00.06,0:04:01.93,*Default,NTP,0,0,0,,话说回来 小夏**
  38. Dialogue: 0,0:04:01.99,0:04:05.05,*Default,NTP,0,0,0,,您又要去那个叫贺兰的人他家是不是?
  39. Dialogue: 0,0:04:05.64,0:04:07.51,*Default,NTP,0,0,0,,是啊 有什么不对吗?
  40. Dialogue: 0,0:04:07.82,0:04:08.75,*Default,NTP,0,0,0,,这可不行
  41. Dialogue: 0,0:04:08.75,0:04:11.71,*Default,NTP,0,0,0,,小夏**您不是要跟别人订婚约了吗?
  42. Dialogue: 0,0:04:11.77,0:04:13.63,*Default,NTP,0,0,0,,请您务必顾虑一下自己的行为
  43. Dialogue: 0,0:04:14.63,0:04:16.57,*Default,NTP,0,0,0,,我头又晕了
  44. Dialogue: 0,0:04:17.07,0:04:18.94,*Default,NTP,0,0,0,,而且她也没把我的话听进去
  45. Dialogue: 0,0:04:19.69,0:04:22.39,*Default,NTP,0,0,0,,小夏** 危险...
  46. Dialogue: 0,0:04:30.78,0:04:31.71,*Default,NTP,0,0,0,,小霞?
  47. Dialogue: 0,0:04:33.10,0:04:33.88,*Default,NTP,0,0,0,,幸好幸好...
  48. Dialogue: 0,0:04:34.23,0:04:37.99,*Default,NTP,0,0,0,,小夏**的身子差点就要被这水洼弄湿了
  49. Dialogue: 0,0:04:38.16,0:04:42.32,*Default,NTP,0,0,0,,好了 请您就照这样踏着小霞走过去吧
  50. Dialogue: 0,0:04:42.41,0:04:43.98,*Default,NTP,0,0,0,,千万别客气 小夏**
  51. Dialogue: 0,0:04:44.26,0:04:46.54,*Default,NTP,0,0,0,,快...
  52. Dialogue: 0,0:04:47.69,0:04:50.27,*Default,NTP,0,0,0,,能够挺身而出保护好小夏**
  53. Dialogue: 0,0:04:50.35,0:04:52.32,*Default,NTP,0,0,0,,小霞我是多么忠心的侍从啊
  54. Dialogue: 0,0:04:52.86,0:04:55.92,*Default,NTP,0,0,0,,我真是太佩服我自己了
  55. Dialogue: 0,0:04:56.02,0:04:58.36,*Default,NTP,0,0,0,,哇咧 我头又晕了
  56. Dialogue: 0,0:04:58.44,0:04:59.43,*Default,NTP,0,0,0,,喂~
  57. Dialogue: 0,0:05:04.03,0:05:08.05,*Default,NTP,0,0,0,,所以啊 我坚持自己的结婚对象要自己去找
  58. Dialogue: 0,0:05:08.46,0:05:11.55,*Default,NTP,0,0,0,,我才不想和我爸爸擅自决定的对象结婚
  59. Dialogue: 0,0:05:11.66,0:05:14.40,*Default,NTP,0,0,0,,可是...那样我就伤脑筋了啊
  60. Dialogue: 0,0:05:14.78,0:05:18.62,*Default,NTP,0,0,0,,你要搞清楚 我又不是特地为了你才结婚的
  61. Dialogue: 0,0:05:18.68,0:05:19.90,*Default,NTP,0,0,0,,话是没错啦
  62. Dialogue: 0,0:05:20.33,0:05:23.05,*Default,NTP,0,0,0,,可是您对那个人到底有什么不满呢?
  63. Dialogue: 0,0:05:23.16,0:05:25.57,*Default,NTP,0,0,0,,他不是一个无可挑剔的结婚对象吗?
  64. Dialogue: 0,0:05:25.93,0:05:27.68,*Default,NTP,0,0,0,,唉 真是可惜
  65. Dialogue: 0,0:05:27.72,0:05:30.43,*Default,NTP,0,0,0,,既然你这么认为 不然你代替我嫁给他好了
  66. Dialogue: 0,0:05:30.49,0:05:31.94,*Default,NTP,0,0,0,,咦 真的可以吗?
  67. Dialogue: 0,0:05:31.96,0:05:32.15,*Default,NTP,0,0,0,,当然可以
  68. Dialogue: 0,0:05:32.82,0:05:36.37,*Default,NTP,0,0,0,,不过 请您不要唬弄我了 小夏**
  69. Dialogue: 0,0:05:36.67,0:05:37.39,*Default,NTP,0,0,0,,为什么会这么说?
  70. Dialogue: 0,0:05:37.61,0:05:39.53,*Default,NTP,0,0,0,,我是真的无所谓哟
  71. Dialogue: 0,0:05:43.14,0:05:45.55,*Default,NTP,0,0,0,,小夏** 这种事情务必让我来
  72. Dialogue: 0,0:05:45.67,0:05:48.21,*Default,NTP,0,0,0,,不用了啦 敲门这点小事我还做得来呢
  73. Dialogue: 0,0:05:50.95,0:05:52.19,*Default,NTP,0,0,0,,您怎么这么说...
  74. Dialogue: 0,0:05:53.67,0:05:56.70,*Default,NTP,0,0,0,,小霞为了能帮上小夏**的忙...
  75. Dialogue: 0,0:05:58.25,0:06:00.24,*Default,NTP,0,0,0,,是如此的尽心尽力耶...
  76. Dialogue: 0,0:06:01.59,0:06:03.15,*Default,NTP,0,0,0,,您这么说实在是太过分了
  77. Dialogue: 0,0:06:04.64,0:06:06.65,*Default,NTP,0,0,0,,好好好 就请你帮我敲门吧
  78. Dialogue: 0,0:06:06.70,0:06:08.58,*Default,NTP,0,0,0,,一切有劳你啰 小霞
  79. Dialogue: 0,0:06:08.98,0:06:10.36,*Default,NTP,0,0,0,,好的 好的
  80. Dialogue: 0,0:06:10.87,0:06:13.12,*Default,NTP,0,0,0,,那么 请您稍等一会儿
  81. Dialogue: 0,0:06:23.20,0:06:26.06,*Default,NTP,0,0,0,,不会吧 连敲个门都用尽你吃奶的力气了
  82. Dialogue: 0,0:06:26.10,0:06:26.66,*Default,NTP,0,0,0,,来了~
  83. Dialogue: 0,0:06:28.44,0:06:29.64,*Default,NTP,0,0,0,,痛死我了
  84. Dialogue: 0,0:06:31.55,0:06:32.54,*Default,NTP,0,0,0,,嗨!
  85. Dialogue: 0,0:06:38.33,0:06:42.31,*Default,NTP,0,0,0,,哈哈哈 我正好在疯着看"恶代官"啦
  86. Dialogue: 0,0:06:42.36,0:06:43.24,*Default,NTP,0,0,0,,恶代官?
  87. Dialogue: 0,0:06:47.86,0:06:49.04,*Default,NTP,0,0,0,,我这地方又小又脏的
  88. Dialogue: 0,0:06:49.10,0:06:50.15,*Default,NTP,0,0,0,,请两位多多包涵
  89. Dialogue: 0,0:06:50.62,0:06:52.71,*Default,NTP,0,0,0,,反正你这地方一点都没变
  90. Dialogue: 0,0:06:52.79,0:06:53.94,*Default,NTP,0,0,0,,来 先喝这一杯吧
  91. Dialogue: 0,0:06:56.22,0:06:58.33,*Default,NTP,0,0,0,,这...这啥东东啊?
  92. Dialogue: 0,0:06:58.40,0:07:00.57,*Default,NTP,0,0,0,,看也知道吧 是茶啊
  93. Dialogue: 0,0:07:01.17,0:07:01.77,*Default,NTP,0,0,0,,茶?
  94. Dialogue: 0,0:07:01.92,0:07:03.79,*Default,NTP,0,0,0,,只是说用咖啡来代替而已
  95. Dialogue: 0,0:07:03.94,0:07:04.77,*Default,NTP,0,0,0,,来 砂糖
  96. Dialogue: 0,0:07:07.60,0:07:10.00,*Default,NTP,0,0,0,,小夏** 像这么可疑的饮料
  97. Dialogue: 0,0:07:10.06,0:07:11.95,*Default,NTP,0,0,0,,应该让我先试过毒才对
  98. Dialogue: 0,0:07:12.18,0:07:13.60,*Default,NTP,0,0,0,,好了给我吧 小夏**
  99. Dialogue: 0,0:07:14.55,0:07:15.78,*Default,NTP,0,0,0,,这话说的太过分了吧
  100. Dialogue: 0,0:07:15.86,0:07:18.17,*Default,NTP,0,0,0,,真是的 你这么说是很失礼的哟 小霞
  101. Dialogue: 0,0:07:18.70,0:07:19.97,*Default,NTP,0,0,0,,来 这是给你的
  102. Dialogue: 0,0:07:21.03,0:07:22.28,*Default,NTP,0,0,0,,谢谢...
  103. Dialogue: 0,0:07:24.75,0:07:27.53,*Default,NTP,0,0,0,,唉 看来这样不行
  104. Dialogue: 0,0:07:28.11,0:07:31.10,*Default,NTP,0,0,0,,不晓得哪里才找得到真正的日本刀
  105. Dialogue: 0,0:07:31.53,0:07:35.50,*Default,NTP,0,0,0,,对了对了 我有样礼物要送给贺兰你哟
  106. Dialogue: 0,0:07:35.92,0:07:37.90,*Default,NTP,0,0,0,,我今天就是为这件事而来的
  107. Dialogue: 0,0:07:38.44,0:07:40.40,*Default,NTP,0,0,0,,咦 小夏**有东西要送我?
  108. Dialogue: 0,0:07:40.48,0:07:42.31,*Default,NTP,0,0,0,,别说那么多了 把手伸出来吧
  109. Dialogue: 0,0:07:43.18,0:07:43.77,*Default,NTP,0,0,0,,像这样吗?
  110. Dialogue: 0,0:07:43.83,0:07:44.72,*Default,NTP,0,0,0,,没错没错
  111. Dialogue: 0,0:07:46.07,0:07:46.50,*Default,NTP,0,0,0,,给
  112. Dialogue: 0,0:07:47.00,0:07:47.65,*Default,NTP,0,0,0,,咦?
  113. Dialogue: 0,0:07:47.91,0:07:49.50,*Default,NTP,0,0,0,,啊...这个是...
  114. Dialogue: 0,0:07:55.43,0:07:56.88,*Default,NTP,0,0,0,,怎么样 喜欢吗?
  115. Dialogue: 0,0:07:57.02,0:07:59.55,*Default,NTP,0,0,0,,哇塞 这不是真的日本刀吗?
  116. Dialogue: 0,0:07:59.64,0:08:00.78,*Default,NTP,0,0,0,,干嘛送我这个啊?
  117. Dialogue: 0,0:08:02.15,0:08:04.67,*Default,NTP,0,0,0,,总之里面好像没下毒的样子
  118. Dialogue: 0,0:08:04.79,0:08:06.47,*Default,NTP,0,0,0,,这不是什么大不了的东西
  119. Dialogue: 0,0:08:06.64,0:08:07.84,*Default,NTP,0,0,0,,就送给贺兰你吧
  120. Dialogue: 0,0:08:07.91,0:08:09.25,*Default,NTP,0,0,0,,咦 你说的是真的吗?
  121. Dialogue: 0,0:08:09.33,0:08:10.30,*Default,NTP,0,0,0,,是真的 你就收下吧
  122. Dialogue: 0,0:08:12.76,0:08:14.09,*Default,NTP,0,0,0,,谢谢你 小夏**
  123. Dialogue: 0,0:08:14.22,0:08:15.38,*Default,NTP,0,0,0,,我一定会好好珍惜它的
  124. Dialogue: 0,0:08:18.46,0:08:20.89,*Default,NTP,0,0,0,,怎...怎么了 不要紧吧你?
  125. Dialogue: 0,0:08:20.96,0:08:23.81,*Default,NTP,0,0,0,,不对 你好像是叫小霞**对吧
  126. Dialogue: 0,0:08:25.26,0:08:27.08,*Default,NTP,0,0,0,,小夏** 拜托哦 小夏**
  127. Dialogue: 0,0:08:27.15,0:08:28.20,*Default,NTP,0,0,0,,这到底是怎么一回事?
  128. Dialogue: 0,0:08:28.29,0:08:30.52,*Default,NTP,0,0,0,,你说要把"那个"要送给他 有没有搞错啊?
  129. Dialogue: 0,0:08:30.81,0:08:32.18,*Default,NTP,0,0,0,,小夏** 小夏**
  130. Dialogue: 0,0:08:32.36,0:08:34.67,*Default,NTP,0,0,0,,你说"怎么一回事"? 就是这么一回事啊
复制代码

作者: aloha20200628    时间: 2024-5-18 08:17

本帖最后由 aloha20200628 于 2024-5-18 08:18 编辑

回复 1# 1139054012

类似帖已有解决方案》http://www.bathome.net/thread-68570-1-1.html
http://www.bathome.net/thread-68580-1-1.html

作者: aloha20200628    时间: 2024-5-18 10:29

本帖最后由 aloha20200628 于 2024-5-18 10:30 编辑

回复 1# 1139054012

一楼示例文件所要替换的数据比较简单,也可用以下代码一步到位,将当前目录下*.ass字幕文件中每行可能包含的 ‘英文双引号对’ 替换为 ‘繁体中文双引号对’,其中调用的sed.exe可从本坛第三方下载,代码存为test.bat运行,须置于被处理的*.ass文件同目录,假设*.ass文件均为简中编码(即记事本中的ANSI编码)
  1. @echo off &for /f "delims=" %%F in ('dir /b/a-d *.ass') do (
  2. sed -r "s/\x22([^\x22]*)\x22/「\1」/g" "%%F">"%%~nF.new%%~xF"
  3. )
  4. pause&exit/b
复制代码

作者: 1139054012    时间: 2024-5-18 11:53

本帖最后由 1139054012 于 2024-5-18 12:16 编辑

回复 5# aloha20200628


感谢回复,已测试ANSI格式可以成功替换

改了下上面帖子之前写的代码,ANSI格式也可以替换
  1. @echo off &setlocal enabledelayedexpansion
  2. for /f "delims=" %%F in ('dir/s/b/a-d *.ass') do (
  3.    set/a "pm=1,qm=1"
  4.    (for /f "usebackq delims=" %%a in ("%%~F") do (
  5.       set "s=%%a"&set "s=!s:......=…!"&set "_s=!s!"
  6.       for %%n in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  7.          if "!_s:~%%n,1!" neq "" (set/a "ls+=%%n"&set "_s=!_s:~%%n!")
  8.       )
  9.       for /L %%n in (1,1,!ls!) do for %%c in (" ", " ", "  ") do if "%%~c"=="!s:~,1!" (
  10.          set "s=!s:~1!"&set/a "ls-=1")
  11.       for /L %%n in (0,1,!ls!) do (
  12.          set "c=!s:~%%n,1!" & if ^!c! == ^" (
  13.             set/a "pm=0-!pm!" &if !pm! equ -1 (set "c=「") else (set "c=」")
  14.          ) else if "!c!" == "'" (set/a "qm=0-!qm!" &if !qm! equ -1 (set "c=‘") else (set "c=’"))
  15.          set "_line=!_line!!c!"
  16.       )
  17.       echo,!_line!&set "_line="&set "ls=0"
  18.    ))>"%%~F.new"
  19. )
  20. endlocal&exit/b
复制代码
这个如果改?
可以不在后缀加.new,不更改原文件名,放到新建文件夹,我把.new删了,直接不运行了
作者: aloha20200628    时间: 2024-5-18 12:17

本帖最后由 aloha20200628 于 2024-5-19 10:23 编辑

回复 6# 1139054012

据楼主所求已订正代码如下,清理了原帖楼主要求的一些专项代码。被替换的结果文件存于当前目录中的新目录 new 下面
注意》如源文件是ANSI编码须删除以下代码第2行,且代码亦须存为ANSI编码;如源文件是utf-8编码则只须将以下代码存为utf-8编码即可
  1. @echo off &setlocal enabledelayedexpansion
  2. chcp 65001>null
  3. md "new" 2>nul
  4. for /f "delims=" %%F in ('dir/s/b/a-d *.ass') do (
  5.    set/a "pm=1"
  6.    (for /f "usebackq delims=" %%a in ("%%~F") do (
  7.       set "s=%%a"&set "_s=!s!"
  8.       for %%n in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  9.          if "!_s:~%%n,1!" neq "" (set/a "ls+=%%n"&set "_s=!_s:~%%n!")
  10.       )
  11.       for /L %%n in (0,1,!ls!) do (
  12.          set "c=!s:~%%n,1!" & if ^!c! == ^" (
  13.             set/a "pm=-!pm!" &if !pm! equ -1 (set "c=「") else (set "c=」")
  14.          )
  15.          set "_line=!_line!!c!"
  16.       )
  17.       echo,!_line!&set "_line="&set "ls=0"
  18.    ))>"new\%%~nxF"
  19. )
  20. chcp 936>nul
  21. endlocal&pause&exit/b
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2