本文以 后缀为 .jpg .mp4 文件为例:
在Windows上,使用PowerShell脚本将所有子文件夹中的 .jpg 文件名称改为与 .mp4 文件一致
$path = "D:\video"
$files = Get-ChildItem -Path $path -Filter "*.jpg" -Recurse
foreach ($file in $files) {
$parentPath = $file.DirectoryName
$fileName = $file.BaseName
$mp4Files = Get-ChildItem -Path $parentPath -Filter "*.mp4"
foreach ($mp4File in $mp4Files) {
Rename-Item -Path $file.FullName -NewName ($mp4File.BaseName + ".jpg")
}
}
注意,请确保将 $path = “D:\video” 替换为您的实际文件夹路径。
这个 PowerShell 脚本会递归地遍历文件夹中的所有 .jpg 文件,并为每个文件在相同文件夹中查找对应的 .mp4 文件。然后将 .jpg 文件重命名为对应的 .mp4 文件名。