| | | | | | | | | | | | | | | | | $current=($env:current).trimend('\'); | | $logfile=$current+'\info.txt'; | | $enc=New-Object System.Text.UTF8Encoding $False; | | $fs=New-Object System.IO.FileStream($logfile, [System.IO.FileMode]::Create); | | $sw=New-Object System.IO.StreamWriter($fs, $enc); | | $reg='[\x21-\x27\x2a-\x3b\x3f-\x7e\x3d]+(\.com|\.cn|\.cc|\.net|\.org|\.top|\.vip)[\x21-\x27\x2a-\x3b\x3f-\x7e\x3d]*'; | | $folders=@(dir -literal $current|?{$_ -is [System.IO.DirectoryInfo]}); | | for($i=0;$i -lt $folders.length;$i++){ | | write-host $folders[$i].Name; | | $files=@(dir -literal $folders[$i].FullName|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}); | | for($j=0;$j -lt $files.length;$j++){ | | $filepath=$files[$j].FullName.Substring($current.length); | | $arr=New-Object -TypeName System.Collections.ArrayList; | | $text=[IO.File]::ReadAllText($files[$j].FullName, $enc); | | $text=[regex]::replace($text, $reg, { | | param($m); | | $it=$m.groups[0].value; | | if($it.length -gt 6){ | | [void]$arr.add($it); | | return ''; | | }else{return $it;} | | }); | | if($arr.count -gt 0){ | | [IO.File]::WriteAllText($files[$j].FullName, $text, $enc); | | $line=$filepath+"`r`n"+($arr -join "`r`n"); | | $sw.WriteLine($line); | | $sw.WriteLine(''); | | $sw.Flush(); | | } | | } | | } | | $sw.Close(); | | $fs.Close();COPY |
|