有时候下载torrent种子文件,名字无意义,所以可以用ps脚本处理一下,重命名为正确的名字,代码如下,需要设置种子文件所在文件夹-
- $Path ="D:\"
- $Filter = '*.torrent'
-
- $ar = New-Object -TypeName System.Collections.ArrayList
-
- function processing_grep( $file ){
-
- #write-host "file_name=" $file
-
- $tmpContent = Get-Content -Encoding utf8 $file
- $movie_name_full=""
-
-
- for ($i=0; $i -le $tmpContent.length; $i++)
- {
-
-
- if($tmpContent[$i] -match "name\d+:(.*?):name") # "name\d+:(.*?):name"
- {
- #write-host ""
- $movie_name_full=$matches[1]
- #write-host "------------------------------------------------------------------------------"
- #write-host $file : " $i " :
- #write-host $file " : " $i " : " $tmpContent[$i] -ForegroundColor yellow -background black
- ###write-host "$spaces-- movie_name_regex = $matches[0] "
- write-host "$spaces-- movie_name_full = $movie_name_full "
- if($ar.Contains($movie_name_full)) {
- ###write-host "$spaces-- 含有重复复名字:$movie_name_full " -ForegroundColor red -background black
- ###"$file , movie_name = $movie_name_full" | Out-File -Append "repeat_torrent.txt"
- } else {
- ###write-host "$spaces-- 添加元素: $movie_name_full " -ForegroundColor green
- ###$ar.Add($movie_name_full)
- ###mv -path "$file" -dest "$movie_name_full.torrent"
- }
-
- #write-host "$spaces------------------------------------------------------------------------------"
- $found = 1
- break
- } elseif($tmpContent[$i] -match "name.utf.*?:(.*?)12:piece") {
- #write-host ""
- $movie_name_full=$matches[1]
- #write-host "------------------------------------------------------------------------------"
- #write-host $file : " $i " :
- #write-host $file " : " $i " : " $tmpContent[$i] -ForegroundColor yellow -background black
- ###write-host "$spaces-- movie_name_regex = $matches[0] "
- write-host "$spaces-- movie_name_full = $movie_name_full "
- if($ar.Contains($movie_name_full)) {
- ###write-host "$spaces-- 含有重复复名字:$movie_name_full " -ForegroundColor red -background black
- ###"$file , movie_name = $movie_name_full" | Out-File -Append "repeat_torrent.txt"
- } else {
- ###write-host "$spaces-- 添加元素: $movie_name_full " -ForegroundColor green
- ###$ar.Add($movie_name_full)
- ###mv -path "$file" -dest "$movie_name_full.torrent"
- }
-
- #write-host "$spaces------------------------------------------------------------------------------"
- $found = 1
- break
-
- } elseif($tmpContent[$i] -match "name\d+:(.*?)piece:") {
- #write-host ""
- $movie_name_full=$matches[1]
- #write-host "------------------------------------------------------------------------------"
- #write-host $file : " $i " :
- #write-host $file " : " $i " : " $tmpContent[$i] -ForegroundColor yellow -background black
- ###write-host "$spaces-- movie_name_regex = $matches[0] "
- write-host "$spaces-- movie_name_full = $movie_name_full "
- if($ar.Contains($movie_name_full)) {
- ###write-host "$spaces-- 含有重复复名字:$movie_name_full " -ForegroundColor red -background black
- ###"$file , movie_name = $movie_name_full" | Out-File -Append "repeat_torrent.txt"
- } else {
- ###write-host "$spaces-- 添加元素: $movie_name_full " -ForegroundColor green
- ###$ar.Add($movie_name_full)
- ###mv -path "$file" -dest "$movie_name_full.torrent"
- }
-
- #write-host "$spaces------------------------------------------------------------------------------"
- $found = 1
- break
-
- } else {
- continue
- write-host "222------------------------------------------------------------------------------"
- write-host $file : " 资源名称找不到,请检查正则表达式是否遗漏。 " : -ForegroundColor red -background black
- cmd /c "pause"
- #exit
- }
- #cmd /c "pause"
-
- }#for
- }
-
-
- ,@(Get-ChildItem -Attributes A -path $Path -Filter $Filter -Recurse | ?{$_.PsIsContainer -eq $false}| %{ processing_grep (escape_path_special_char_to____string_for_get_childitem ($_.FullName) )} )
复制代码
|