本帖最后由 zaqmlp 于 2022-4-4 21:03 编辑
bat存为ANSI/GB2312编码- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000
- set "current=%cd%"
- powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
- pause
- exit
- #>
- $srt_ext=@(".chs.srt",".中英.srt",".双语.srt");
- $mp4_ext=@("_batch.mp4","_x264.mp4","_压制.mp4");
-
- write-host '1、处理srt';
- write-host '2、处理mp4';
- $choice1='';
- while($choice1 -notmatch '^(1|2)$'){
- $choice1=read-host '输入数字序号并回车';
- }
-
- $e=".srt";$arr=@($srt_ext|%{$_.ToLower()});$n=1;$ee=@{};
- if($choice1 -eq '2'){$e=".mp4";$arr=@($mp4_ext|%{$_.ToLower()});}
- $current=get-item -liter $env:current;
- $files=@(dir -literal $current.FullName -recurse|?{($e -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- $dic=New-Object 'System.Collections.Generic.Dictionary[string, Object]';
- for($i=0;$i -lt $files.length;$i++){
- $key=$e;
- $fname=$files[$i].Name.ToLower();
- for($j=0;$j -lt $arr.length;$j++){
- if($fname.EndsWith($arr[$j])){
- $key=$arr[$j];
- break;
- }
- }
- if(-not $dic.ContainsKey($key)){
- [System.Collections.ArrayList]$brr=@();
- $dic.add($key, $brr);
- $ee.add($n.ToString(), $key);
- $n++;
- }
- [void]$dic[$key].add($files[$i]);
- }
-
- write-host '选择删除类型';
- foreach($k in ($ee.Keys|sort)){
- write-host ("{0}、{1}" -f $k,$ee[$k]);
- }
- $choice2=read-host '输入数字序号并回车';
- for($i=0;$i -lt $dic[$ee[$choice2]].count;$i++){
- write-host ($dic[$ee[$choice2]][$i].FullName.SubString($current.FullName.length));
- remove-item -literal $dic[$ee[$choice2]][$i].FullName -force -ErrorAction SilentlyContinue;
- }
复制代码
|