有没有办法批量删除 900ish 文件的部分文件名?
Is there a way I can bulk remove part of a filename for 900ish files?
需要一种删除部分文件名的方法。
已经尝试了一些基本的记事本++东西哈哈
https://i.imgur.com/SM8QbWq.jpg
图片主要是我需要的!
例如
sevenberry_island_paradise-SB-4131D1-4-S5090015(.jpg)
到
sevenberry_island_paradise-SB-4131D1-4(.jpg)
商品代码在SB-之后,例如4131D1-4,这之后的一切我都不想要。
从所有这些文件中删除它的任何方法都将是一个巨大的巨大帮助!!
谢谢!!
问题不适合作为 posted,您需要 post 您尝试过的内容,并寻求有关您自己的代码和遇到的任何错误消息或意外结果的帮助。话虽这么说,我看到了你的问题,想出一个解决方案似乎很有趣,所以我做到了。
此代码将查找指定目录中的所有文件(您可以将 -Recurse
参数添加到 Get-ChildItem
行以获取所有子目录中的文件)并将它们全部重命名,删除文件名末尾使用 RegEx.
在尝试此操作之前,复制 您的文件。我已尽力创建一个适用于您所描绘的文件名的解决方案,但如果文件名与所描绘的文件名有很大不同,那么您可能会得到意想不到的结果。 先做个备份。
# Specify the path in which all of your jpgs are stored
$path = 'C:\Path\To\Jpgs'
# Get all of the files we want to change, and only return files that have the .jpg extension
$jpgs = Get-ChildItem -Path "$path" <#-Recurse#> | Where-Object {$_.Extension -eq '.jpg'}
# Perform the same steps below on every file that we got above by using foreach
foreach ($jpg in $jpgs) {
# Store the original file name in a variable for working on
[string]$originalBaseName = "$($jpg.BaseName)"
# Use RegEx to split the file name
[string]$substringToReplace = ($originalBaseName -split '-[0-9]+-')[1]
# Re-add the '-' to the string which you want to remove from the file name
[string]$substringToReplace = '-' + $substringToReplace
# Remove the portion of the file name you want gone
[string]$newBaseName = $originalBaseName -replace "$substringToReplace",''
# Rename the file with the new file name
Rename-Item -Path "$($jpg.FullName)" -NewName "$newBaseName$($jpg.Extension)"
}
需要一种删除部分文件名的方法。
已经尝试了一些基本的记事本++东西哈哈
https://i.imgur.com/SM8QbWq.jpg
图片主要是我需要的!
例如
sevenberry_island_paradise-SB-4131D1-4-S5090015(.jpg) 到 sevenberry_island_paradise-SB-4131D1-4(.jpg)
商品代码在SB-之后,例如4131D1-4,这之后的一切我都不想要。
从所有这些文件中删除它的任何方法都将是一个巨大的巨大帮助!!
谢谢!!
问题不适合作为 posted,您需要 post 您尝试过的内容,并寻求有关您自己的代码和遇到的任何错误消息或意外结果的帮助。话虽这么说,我看到了你的问题,想出一个解决方案似乎很有趣,所以我做到了。
此代码将查找指定目录中的所有文件(您可以将 -Recurse
参数添加到 Get-ChildItem
行以获取所有子目录中的文件)并将它们全部重命名,删除文件名末尾使用 RegEx.
复制 您的文件。我已尽力创建一个适用于您所描绘的文件名的解决方案,但如果文件名与所描绘的文件名有很大不同,那么您可能会得到意想不到的结果。 先做个备份。
# Specify the path in which all of your jpgs are stored
$path = 'C:\Path\To\Jpgs'
# Get all of the files we want to change, and only return files that have the .jpg extension
$jpgs = Get-ChildItem -Path "$path" <#-Recurse#> | Where-Object {$_.Extension -eq '.jpg'}
# Perform the same steps below on every file that we got above by using foreach
foreach ($jpg in $jpgs) {
# Store the original file name in a variable for working on
[string]$originalBaseName = "$($jpg.BaseName)"
# Use RegEx to split the file name
[string]$substringToReplace = ($originalBaseName -split '-[0-9]+-')[1]
# Re-add the '-' to the string which you want to remove from the file name
[string]$substringToReplace = '-' + $substringToReplace
# Remove the portion of the file name you want gone
[string]$newBaseName = $originalBaseName -replace "$substringToReplace",''
# Rename the file with the new file name
Rename-Item -Path "$($jpg.FullName)" -NewName "$newBaseName$($jpg.Extension)"
}