【发布时间】:2018-12-17 10:11:29
【问题描述】:
我正在尝试将文件从一个目录复制到另一个目录并重命名它们。目标文件夹的文件被删除并且文件被复制,但不幸的是我的脚本的重命名部分没有做任何事情。没有显示错误。
#Set variables
[string]$source = "C:\temp\Photos\Original\*"
[string]$destination = "C:\temp\Photos\Moved\"
#Delete original files to avoid conflicts
Get-ChildItem -Path $destination -Include *.* -Recurse | foreach { $_.Delete()}
#Copy from source to destination
Copy-item -Force -Recurse -Verbose $source -Destination $destination
Get-ChildItem -Path $destination -Include *.jpg | rename-item -NewName { $_.Name -replace '-', ' ' }
目前我只是想用空格替换连字符,但我还需要从文件名的末尾删除W,当我可以让它工作时。
示例原始文件名:First-Last-W.jpg
所需文件名示例:First Last.jpg
【问题讨论】:
标签: regex powershell powershell-4.0