标题: [文件操作] [已解决]批处理根据字幕文件前的[]创建子目录,把后缀符合条件的移动到二级目录? [打印本页]
作者: 1139054012 时间: 2024-10-3 13:56 标题: [已解决]批处理根据字幕文件前的[]创建子目录,把后缀符合条件的移动到二级目录?
前提,文件后缀不一定是*.ass,有可能*.ssa,有可能*.srt,三种条件,这里只示范*.ass后缀
文件名称
[KitaujiSub] Make Heroine ga Oosugiru! [01][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕01.CHI.ass
[KitaujiSub] Make Heroine ga Oosugiru! [01][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕02.CHI.ass
[KitaujiSub] Make Heroine ga Oosugiru! [02][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕01.CHI.ass
[KitaujiSub] Make Heroine ga Oosugiru! [02][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕02.CHI.ass
[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 01 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕01.CHI.ass
[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 01 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕02.CHI.ass
[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 02 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕01.CHI.ass
[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 02 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕02.CHI.ass
文件列表demo下载
如果以上文件名如果包含_字幕01.CHI,_字幕02.CHI的
新建文件夹,文件名第一个[]文件夹
KitaujiSub
Nekomoe kissaten&LoliHouse
里面再新建文件夹,名为【简体】
把包含_字幕01.CHI的移动到这个文件夹
里面再新建文件夹,名为【繁体】
把包含_字幕02CHI的移动到这个文件夹,并重命名删除
得到结果
KitaujiSub\简体\[KitaujiSub] Make Heroine ga Oosugiru! [01][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕01.CHI.ass
KitaujiSub\简体\[KitaujiSub] Make Heroine ga Oosugiru! [02][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕01.CHI.ass
KitaujiSub\繁体\[KitaujiSub] Make Heroine ga Oosugiru! [01][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕02.CHI.ass
KitaujiSub\繁体\[KitaujiSub] Make Heroine ga Oosugiru! [02][WebRip][HEVC_AAC][CHS_JP&CHT_JP]_字幕02.CHI.ass
Nekomoe kissaten&LoliHouse\简体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 01 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕01.CHI.ass
Nekomoe kissaten&LoliHouse\简体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 02 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕01.CHI.ass
Nekomoe kissaten&LoliHouse\繁体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 01 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕02.CHI.ass
Nekomoe kissaten&LoliHouse\繁体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 02 [WebRip 1080p HEVC-10bit AAC ASSx2]_字幕02.CHI.ass
移动到对应文件夹后,把所有包括_字幕01.CHI和_字幕02.CHI都删除
最终结果是
得到结果
KitaujiSub\简体\[KitaujiSub] Make Heroine ga Oosugiru! [01][WebRip][HEVC_AAC][CHS_JP&CHT_JP].ass
KitaujiSub\简体\[KitaujiSub] Make Heroine ga Oosugiru! [02][WebRip][HEVC_AAC][CHS_JP&CHT_JP].ass
KitaujiSub\繁体\[KitaujiSub] Make Heroine ga Oosugiru! [01][WebRip][HEVC_AAC][CHS_JP&CHT_JP].ass
KitaujiSub\繁体\[KitaujiSub] Make Heroine ga Oosugiru! [02][WebRip][HEVC_AAC][CHS_JP&CHT_JP].ass
Nekomoe kissaten&LoliHouse\简体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 01 [WebRip 1080p HEVC-10bit AAC ASSx2].ass
Nekomoe kissaten&LoliHouse\简体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 02 [WebRip 1080p HEVC-10bit AAC ASSx2 .ass
Nekomoe kissaten&LoliHouse\繁体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 01 [WebRip 1080p HEVC-10bit AAC ASSx2].ass
Nekomoe kissaten&LoliHouse\繁体\[Nekomoe kissaten&LoliHouse] Make Heroine ga Oosugiru! - 02 [WebRip 1080p HEVC-10bit AAC ASSx2].ass
作者: ppll2030 时间: 2024-10-3 14:45
本帖最后由 ppll2030 于 2024-10-3 19:29 编辑
更新,添加移动后修改文件名
把代码保存ANSI编码为bat文件,跟字幕文件放在一起,运行即可。- @echo off
- for /f "delims=" %%i in ('dir /b /a-d "*_字幕01*"') do (
- set "str=%%i"
- setlocal enabledelayedexpansion
- for /f "delims=[]" %%a in ("!str!") do (
- md "%%~nxa\简体" 2>nul
- move "!str!" "%%~nxa\简体\!str:_字幕01.CHI=!"
- )
- endlocal
- )
- for /f "delims=" %%i in ('dir /b /a-d "*_字幕02*"') do (
- set "str=%%i"
- setlocal enabledelayedexpansion
- for /f "delims=[]" %%a in ("!str!") do (
- md "%%~nxa\繁体" 2>nul
- move "!str!" "%%~nxa\繁体\!str:_字幕02.CHI=!"
- )
- endlocal
- )
- pause
复制代码
作者: 1139054012 时间: 2024-10-3 16:10
回复 2# ppll2030
谢谢回复,可以移动指定文件夹,请问可以最后删除下文件名后的_字幕01.CHI和_字幕02.CHI吗?
作者: aloha20200628 时间: 2024-10-3 16:25
回复 1# 1139054012 - @echo off &setlocal &for /f "delims=" %%F in ('dir /b/a-d *.ass *.srt *.ssa') do (
- for /f "tokens=1 delims=[]" %%a in ("%%F") do for /f "tokens=1-2 delims=字幕" %%x in ("%%~nF") do (
- md "%%a" &set "F=%%F" &set "a=%%a" &set "x=%%x"
- setlocal enabledelayedexpansion &set "x=!x:~,-1!"
- if /i "01.chi"=="%%y" md "!a!\简体" &move "!F!" "!a!\简体\!x!%%~xF"
- if /i "02.chi"=="%%y" md "!a!\繁体" &move "!F!" "!a!\繁体\!x!%%~xF"
- endlocal
- )) 2>nul
- endlocal&pause&exit/b
复制代码
作者: 77七 时间: 2024-10-3 18:03
- @echo off
- rem 保存为ansi编码
- cd /d "%~dp0"
- for /f "delims=" %%i in ('dir /b /a-d *.ass *.ssa *.srt') do (
- set file=%%i
- for /f "tokens=1 delims=[]" %%a in ("%%~ni") do (
- set folder=%%a
- setlocal enabledelayedexpansion
- if "!file:_字幕01.chi=!" neq "!file!" (
- md "!folder!\简体" 2>nul
- move "!file!" "!folder!\简体\!file:_字幕01.chi=!"
- ) else if "!file:_字幕02.chi=!" neq "!file!" (
- md "!folder!\繁体" 2>nul
- move "!file!" "!folder!\繁体\!file:_字幕02.chi=!"
- )
- endlocal
- )
- )
- pause
复制代码
作者: qixiaobin0715 时间: 2024-10-8 12:34
本帖最后由 qixiaobin0715 于 2024-10-8 12:43 编辑
好像用不着那么多for循环,一个就够了,经测试没发现问题:- @echo off
- for /f "tokens=1* delims=[]" %%i in ('dir /b /a-d *字幕0*.ass *字幕0*.ssa *字幕0*.srt') do (
- set "str=%%j"
- set "str1=%%i"
- setlocal enabledelayedexpansion
- if not "!str1!"=="!str2!" (md "!str1!\简体" "!str1!\繁体")
- if "!str!"=="!str:_字幕01.CHI=!" (
- move "[!str1!]!str!" "!str1!\繁体\[!str1!]!str:_字幕02.CHI=!">nul
- ) else (
- move "[!str1!]!str!" "!str1!\简体\[!str1!]!str:_字幕01.CHI=!">nul
- )
- endlocal
- set "str2=%%i"
- )
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |