我有几个文件夹包含 mp3 文件(文件夹名称为 CD#1 CD#2),每个文件夹中有几个文件。我重命名了专辑名称并更改了曲目编号,这样我的 iPod 就可以将其存储为一本长有声读物。
但是标题名称混乱了,我想重命名标题以便显示曲目 1、曲目 2 等。
我尝试使用 mp3tag,但无法创建动态标题名称(即每个文件都应有下一个编号的曲目 1、曲目 2)。
有什么方法可以做到这一点?
答案1
如果你已经有了正确的曲目编号,你可以尝试使用易达标:首先,重命名文件以包含曲目号,然后将曲目号作为标题的一个元素读入标题字段。
具体来说:使用重命名模式Track %n
,然后使用模式读回%t
。
备份文件在尝试该解决方案之前!
答案2
2021 年,包含下载的视频包的硬盘目录结构被破坏了。
我使用了一个深度恢复程序,它恢复了所有单个文件以及多个旧删除文件的副本,但文件夹不见了,文件名被重命名为通用文件名。我最终重新下载了所有我能下载的内容。
但现在我需要的文件不再存在于网络上,但可能存在于该档案中。我花了昨天和今天早上的时间查看各种“将文件重命名为标题”的代码,以下是我删除所有不必要的操作后得出的结果。
我添加了错误检查以跳过标题为 $null 的文件或已重命名为该标题的文件。文件名中的非法字符将被替换为下划线“_”。我添加了一个计数器以防有多个具有相同标题的文件,并将该数字附加到文件名中。
我花了一点时间才明白我所学习的示例代码中实际上不需要什么。$PrevT 仅用于调试,这样我才能看到它在文件列表中的进度。
$file = ""
$Title = ""
$blah = 0
#$PrevT = ""
#$illegalchars2 = [string]::join('',([System.IO.Path]::GetInvalidFileNameChars())) -replace '\\','\\'
$illegalchars2 = '"<>|:*?\\/'
$LocalDir = 'K:\recup_folders\recup_dir.1\temp\'
$FType = '.mp4'
$AllFiles = Get-ChildItem $LocalDir -Filter *.mp4
$ShellApplication = New-Object -ComObject Shell.Application
foreach ($SingleFile in $AllFiles)
{
$blah = $blah + 1
$folder = ShellApplication.Namespace($SingleFile.Directory.FullName)
$file = $folder.ParseName($SingleFile.Name)
$Title = $file.ExtendedProperty('System.Title')
#$FixT = ([char[]]$Title | where { [IO.Path]::GetinvalidFileNameChars() -notcontains $_ }) -join ''
$FixT = $Title
$FixedT = $FixT -replace "[$illegalchars2]",'_'
if ($null -ne $Title)
{
$OldName = "$LocalDir$Singlefile"
$NewName = "$LocalDir$FixedT$FType"
'-----------------'
#"Previous: $PrevT"
"Current File: $Singlefile"
"Unfixed Title: $Title"
"FixedT: $FixedT"
"OldName: $OldName"
if ($OldName -eq $NewName)
{ 'Skipping file already fixed.' }
else
{
if ((Test-Path -Path $NewName -PathType Leaf))
{
"Repeat File detected: $NewName"
$NewName = "$LocalDir$FixedT($blah)$FType"
}
"Final New Name: $NewName"
Rename-Item $OldName -NewName $NewName
'----Done---------
'
}
#$PrevT = $Title
}
else { "Skipping blank Title file: $Singlefile" }
}
示例输出:
-----------------
Current File: 00PM - Four Points by Sheraton Orlando ✅.mp4
Unfixed Title: Flat Earth Meetup Florida - April 14 - 7:00PM - Four Points by Sheraton Orlando ✅
FixedT: Flat Earth Meetup Florida - April 14 - 7_00PM - Four Points by Sheraton Orlando ✅
OldName: K:\recup_folders\recup_dir.1\temp\00PM - Four Points by Sheraton Orlando ✅.mp4
Final New Name: K:\recup_folders\recup_dir.1\temp\Flat Earth Meetup Florida - April 14 - 7_00PM - Four Points by Sheraton Orlando ✅.mp4
----Done---------
-----------------
Current File: Black Death talks Flat Earth on Heavy Metal Relics ✅.mp4
Unfixed Title: Black Death talks Flat Earth on Heavy Metal Relics ✅
FixedT: Black Death talks Flat Earth on Heavy Metal Relics ✅
OldName: K:\recup_folders\recup_dir.1\temp\Black Death talks Flat Earth on Heavy Metal Relics ✅.mp4
Skipping file already fixed.
-----------------
Current File: f11860480.mp4
Unfixed Title: Flat Earth Man "Welcome to the Satellite Hoax" ✅
FixedT: Flat Earth Man _Welcome to the Satellite Hoax_ ✅
OldName: K:\recup_folders\recup_dir.1\temp\f11860480.mp4
Final New Name: K:\recup_folders\recup_dir.1\temp\Flat Earth Man _Welcome to the Satellite Hoax_ ✅.mp4
----Done---------
-----------------
Current File: f11981680.mp4
Unfixed Title: Flat Earth Man "Welcome to the Satellite Hoax" ✅
FixedT: Flat Earth Man _Welcome to the Satellite Hoax_ ✅
OldName: K:\recup1\recup_folders\recup_dir.1\temp\f11981680.mp4
Repeat File detected: K:\recup_folders\recup_dir.1\temp\Flat Earth Man _Welcome to the Satellite Hoax_ ✅.mp4
Final New Name: K:\recup_folders\recup_dir.1\temp\Flat Earth Man _Welcome to the Satellite Hoax_ ✅(4).mp4
----Done---------
-----------------
Current File: f13881504.mp4
Unfixed Title: Example: <of> /bad\ *bad?
FixedT: Example_ _of_ _bad_ _bad_
OldName: K:\recup_folders\recup_dir.1\temp\f13881504.mp4
Final New Name: K:\recup_folders\recup_dir.1\temp\Example_ _of_ _bad_ _bad_.mp4
----Done---------
Skipping blank Title file: f18489568.mp4
-----------------
Current File: Rock and Roll Flat Earth Song Music - The Zetetic Astronomers by Neo Retros - Mark Sargent ✅.mp4
Unfixed Title: Rock and Roll Flat Earth Song / Music - The Zetetic Astronomers by Neo Retros - Mark Sargent ✅
FixedT: Rock and Roll Flat Earth Song _ Music - The Zetetic Astronomers by Neo Retros - Mark Sargent ✅
OldName: K:\recup_folders\recup_dir.1\temp\Rock and Roll Flat Earth Song Music - The Zetetic Astronomers by Neo Retros - Mark Sargent ✅.mp4
Final New Name: K:\recup_folders\recup_dir.1\temp\Rock and Roll Flat Earth Song _ Music - The Zetetic Astronomers by Neo Retros - Mark Sargent ✅.mp4
----Done---------
我曾经通过从每个帖子中选取一个关键部分来解决这个问题:
- https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3
- https://virot.eu/cleaning-downloaded-filenames-of-invalid-characters/ https://adamtheautomator.com/powershell-check-if-file-exists/
- https://stackoverflow.com/questions/23066783/how-to-strip-illegal-characters-before-trying-to-save-filenames
- https://anjansp.blogspot.com/2016/07/use-powershell-to-check-for-illegal.html https://www.youtube.com/watch?v=dBvqrmd6Srk