本帖最后由 pcl_test 于 2017-1-9 15:16 编辑
- @echo off
- powershell /? >nul 2>&1||(echo;系统没有自带或未安装powershell&pause&exit)
- powershell ^
- function DelVirusCodes($htmlfile, $encoding){^
- $text=[IO.File]::ReadAllText($htmlfile, [Text.Encoding]::GetEncoding($encoding));^
- if($text -match '[\s\S]+^<\/html^>'){return $matches[0]};^
- }^
- ^<# 指定以哪种编码读写html文件,如utf-8,gbk,gb2312,utf-16等^
- 具体支持的编码可参看https://msdn.microsoft.com/zh-cn/library/system.text.encoding.aspx #^>^
- $cs = 'utf-8';^
- ls . *.htm -r^|%%{^
- write-host ('正在修复'+$_.FullName);^
- [IO.File]::WriteAllText(^
- ($_.DirectoryName+'\New_'+$_.Name),^
- (DelVirusCodes $_.FullName $cs),^
- [Text.Encoding]::GetEncoding($cs))^
- }
- pause
复制代码
|