需要一种删除文件名部分的方法。
已经尝试过一些Basic notepad ++东西大声笑
https://i.imgur.com/SM8QbWq.jpg
图像主要显示我所需要的!
例如
sevenberry_island_paradise-SB-4131D1-4-S5090015(.jpg)至sevenberry_island_paradise-SB-4131D1-4(.jpg)
项目代码在SB-之后,例如4131D1-4,此后我不想要的所有内容。
从所有这些文件中删除此文件的任何方式都将带来巨大的巨大帮助!
谢谢!
该问题不适合发布,您需要发布尝试过的内容,并寻求有关您自己的代码以及遇到的任何错误消息或意外结果的帮助。话虽如此,我看到了您的问题,找到解决方案似乎很有趣,所以我做到了。
此代码将找到指定目录内的所有文件(您也可以在-Recurse
行中添加Get-ChildItem
参数以获取所有子目录中的文件)并全部重命名,并使用删除文件名的结尾正则表达式
首先备份。
# 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)"
}