简体   繁体   English

无法在Synology上的共享文件夹位置中使用重命名项重命名子目录中的文件

[英]Cannot rename files in sub directories with rename-item in Shared Folder location on Synology

I have several .mkv files on a Synology NAS in sub directories of a Shared Folder that have the following .partial~ extension appended at the end. 我在Synology NAS上的共享文件夹的子目录中有几个.mkv文件,这些文件的末尾附加了以下.partial~扩展名。

I am trying to remove .partial~ from the end of these files, and ignore all other files located within such as .jpg 我正在尝试从这些文件的末尾删除.partial~ ,而忽略位于其中的所有其他文件,例如.jpg

Folder\\File Structure Eg: 文件夹\\文件结构,例如:

\\\\NAS\\SharedFolder\\Subdirectory1\\Subdirectory2\\file.mkv.partial~ \\\\ NAS \\ SharedFolder \\ Subdirectory1 \\ Subdirectory2 \\ file.mkv.partial〜

\\\\NAS\\SharedFolder\\Subdirectory1\\file.mkv.partial~ \\\\ NAS \\ SharedFolder \\ Subdirectory1 \\ file.mkv.partial〜

\\\\NAS\\SharedFolder\\Subdirectory1\\file.jpg \\\\ NAS \\ SharedFolder \\ Subdirectory1 \\ file.jpg

I have created the following powershell script strippartialext.ps1 that works correctly when run on my Windows 10 PC from within Subdirectory1 or Subdirectory2: 我创建了以下strippartialext.ps1脚本strippartialext.ps1 ,当在Windows 10 PC上的strippartialext.ps1中运行该脚本strippartialext.ps1 ,它们可以正常运行:

\\\\NAS\\SharedFolder\\Subdirectory1\\strippartialext.ps1 [WORKS HERE] \\\\ NAS \\ SharedFolder \\ Subdirectory1 \\ strippartialext.ps1 [在此处工作]

\\\\NAS\\SharedFolder\\Subdirectory1\\Subdirectory2\\strippartialext.ps1 [WORKS HERE] \\\\ NAS \\ SharedFolder \\ Subdirectory1 \\ Subdirectory2 \\ strippartialext.ps1 [在此处工作]

It strips out everything below either (and into subdirectories below) but does not work when run from the top SharedFolder location: 它会剥离下面的任何内容(以及下面的子目录),但是从顶部SharedFolder位置运行时不起作用:

\\\\NAS\\SharedFolder\\strippartialext.ps1 [DOES NOT WORK HERE] \\\\ NAS \\ SharedFolder \\ strippartialext.ps1 [在此无效]

Get-ChildItem -File -Recurse | % { Rename-Item -Path $_.PSPath -NewName $_.Name.replace(".partial~","")}

I get the following errors when running the .ps1 file from the SharedFolder location: 从SharedFolder位置运行.ps1文件时,出现以下错误:

Rename-Item : Cannot rename because item at 'Microsoft.PowerShell.Core\\FileSystem::\\NAS\\sharedfolder\\Sub Directory1\\file.jpg' does not exist. Rename-Item:无法重命名,因为“ Microsoft.PowerShell.Core \\ FileSystem :: \\ NAS \\ sharedfolder \\ Sub Directory1 \\ file.jpg”中的项目不存在。 At \\NAS\\sharedfolder\\strippartialext.ps1:1 char:36 + ... curse | 在\\ NAS \\ sharedfolder \\ strippartialext.ps1:1 char:36 + ... curse | % { Rename-Item -Path $ .PSPath -NewName $ .Name.replace(".pa ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Rename-Item], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand %{Rename-Item -Path $ .PSPath -NewName $ .Name.replace(“。pa ... + ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [Rename-Item],PSInvalidOperationException + FullyQualifiedErrorId: InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand

I would like to know how to get this file to run from the SharedFolder location as I would only have to run this script once to cover all of my files instead of hundred of times separately within each Sub directory Folder. 我想知道如何从SharedFolder位置运行此文件,因为我只需要运行一次此脚本即可覆盖我的所有文件,而不必在每个子目录文件夹中分别运行数百次。

The Rename-Item cmdlet accepts piped input, so I'd try: Rename-Item cmdlet接受管道输入,因此我尝试:

Get-ChildItem -File -Recurse "*.partial~" | 
    Rename-Item -NewName {$_.Name.replace(".partial~","")} -WhatIf

If the output looks OK remove hte -WhatIf 如果输出看起来-WhatIf删除hte -WhatIf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM