本帖最后由 zaqmlp 于 2020-7-31 01:18 编辑
- <# :
- cls
- @echo off
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~f0'"
- pause
- exit
- #>
- $self=get-item -liter $args[0];
- $path=$self.Directory.FullName
- $len=15;
- $newfolder=$path+'\#result';
- if(-not (test-path -liter $newfolder)){[void](md $newfolder)};
- $files=@(dir -liter $path|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i].Name;
- [System.Collections.ArrayList]$s=@();
- $dic=New-Object 'System.Collections.Generic.Dictionary[string,string]';
- $enc=[Text.Encoding]::Default;
- $text=[IO.File]::ReadAllLines($files[$i].FullName, $enc);
- for($j=0;$j -lt $text.count;$j++){
- $tmpline=$text[$j] -replace '[^\u4e00-\u9fa5]','';
- $a=$tmpline.length;
- $line=$tmpline;
- if($len -lt $a){$line=$tmpline.substring(0, $len);}
- if(-not $dic.ContainsKey($line)){
- $dic.add($line,'');
- [void]$s.add($text[$j]);
- };
- };
- $newfile=$newfolder+'\'+$files[$i].Name;
- [IO.File]::WriteAllLines($newfile, $s, $enc);
- };
复制代码
|