只需尝试更改以开头的一堆文件
02. SongName.Mp3
02 - OtherName.Mp3
02 MoreNames.Mp3
03. Song.mp3
03 - Songs.mp3
到
SongName.Mp3
OtherName.Mp3
MoreNames.Mp3
Song.mp3
Songs.mp3
我知道这是一个非常简单的[ren]命令,但它逃脱了我的大脑。我在文件夹上使用file> open> powershell,因此无需使用dir或cd或其他任何内容。
答案 0 :(得分:1)
Get-ChildItem *.mp3 | Rename-Item -NewName { $_.Name -replace '^[^\p{L}]+' } -WhatIf
注意:上方命令中的-WhatIf
common parameter会预览该操作。确定操作将执行您想要的操作后,请删除-WhatIf
。
以上方法通过从文件名中删除第一个字母(*.mp3
前的 之前的所有字符来重命名\p{L}
文件;名称已经以字母开头的文件将保持不变。
使用的技术:
传递到{ ... }
的{{3}}(-NewName
),对于由Get-ChildItem
发出的每个delay-bind script block输入对象进行绑定评估自动变量$_
基于正则表达式的System.IO.FileInfo
。
答案 1 :(得分:1)
我会解决的。假设所有文件均为mp3,则将数字,点,破折号和空格全部替换为空。 (或“ copy-item -destination”)
# test files
# echo hi | set-content '02. SongName.Mp3','02 - OtherName.Mp3','02 MoreNames.Mp3','03. Song.mp3','03 - Songs.mp3'
dir *.mp3 | rename-item -newname { ($_.basename -replace '[\d\.\- ]') + '.mp3' } -whatif
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/02 - OtherName.Mp3 Destination: /Users/js/foo/OtherName.mp3".
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/02 MoreNames.Mp3 Destination: /Users/js/foo/MoreNames.mp3".
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/02. SongName.Mp3 Destination: /Users/js/foo/SongName.mp3".
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/03 - Songs.mp3 Destination: /Users/js/foo/Songs.mp3".
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/03. Song.mp3 Destination: /Users/js/foo/Song.mp3".
答案 2 :(得分:-1)
Get-ChildItem *.mp3 |
Where-Object Name -match '^.{4}(.+).\.(.+)$' |
Copy-Item -Destination { $Matches.1 + '.' + $Matches.2 }
这适用于我想做的事情。特别说明,它复制文件,而不重命名现有文件。