這個怎麼樣:
# Create array of filenames
$files =
"[abs] anima.some e147 name [480p].avi",
"anima.some e147 name #anim group .avi",
"anima.some e147 name [480p].avi",
"anima some e147 name [480p].avi"
# Setup patterns to match against
$pattern1 = "\[\w+\] ([^.]+).([\w]+) ([\S]+) [\w]+ \[[\w]+\].avi"
$pattern2 = "([^.\s]+).([\w]+) ([\S]+) .*.avi"
# Loop through file names and attempt matching
foreach($f in $files)
{
if($f -match $pattern1)
{
$string = (Get-Culture).TextInfo.ToTitleCase($matches[1]) + " " + $matches[2] + " " + $matches[3] + ".avi"
$string
}
elseif($f -match $pattern2)
{
$string = (Get-Culture).TextInfo.ToTitleCase($matches[1]) + " " + $matches[2] + " " + $matches[3] + ".avi"
$string
}
else
{
"unmatched file: " + $f
}
}
輸出是:
Anima some e147.avi
Anima some e147.avi
Anima some e147.avi
Anima some e147.avi
PowerShell的實際上是不能處理文件名以'[]'在其中,所以你需要做的不僅僅是重命名和正則表達式,就像使用一些.NET類一樣。 – SpellingD
感謝您的信息,如果您可以在PowerShell中使用.NET進行這項工作,那將是一個可以接受的解決方案。 – justinf