本帖最后由 zaqmlp 于 2020-7-21 20:02 编辑
- <# :
- cls
- @echo off
- rem 替换
- mode con lines=5000
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
- pause
- exit
- #>
- $path=$args[0].trimend('\');
- $txtfile=".\a.txt";
- $oldfolder="E:\yyy\epub解包后";
- $ext=@('.html', '.xhtml');
-
- $txtfile=$txtfile -replace '^\.',$path;
- if(-not (test-path -liter $txtfile)){Write-host ('"'+$txtfile+'" not found');exit;};
- if(-not (test-path -liter $oldfolder)){Write-host ('"'+$oldfolder+'" not found');exit;};
- $Utf8NoBom=New-Object System.Text.UTF8Encoding $False;
- $text=[IO.File]::ReadAllLines($txtfile, $Utf8NoBom);
- $folders=@(dir -liter $oldfolder|?{$_ -is [System.IO.DirectoryInfo]});
- for($i=0;$i -lt $folders.count;$i++){
- write-host $folders[$i].FullName;
- $files=@(dir -liter $folders[$i].FullName -recurse|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($j=0;$j -lt $files.count;$j++){
- write-host $files[$j].FullName.substring($folders[$i].FullName.length);
- $htmltext=[IO.File]::ReadAllText($files[$j].FullName, $Utf8NoBom);
- for($k=0;$k -lt $text.count;$k++){
- $arr=$text[$k] -split '\t',2;
- $htmltext=$htmltext.replace($arr[0],$arr[1]);
- };
- [IO.File]::WriteAllText($files[$j].FullName, $htmltext, $Utf8NoBom);
- };
- };
复制代码
|