regex - Powershell重命名文件不起作用 - 没有错误
问题描述
我正在尝试将文件从一个目录复制到另一个目录并重命名它们。目标文件夹的文件被删除并且文件被复制,但不幸的是我的脚本的重命名部分没有做任何事情。没有显示错误。
#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
,但当我可以让它工作时,我还需要从文件名的末尾删除 a 。
示例原始文件名:First-Last-W.jpg
示例所需的文件名:First Last.jpg
解决方案
更改-include
参数-filter
Get-ChildItem -Path $destination -Include *.jpg
include 是基于 cmdlet
Get-ChildItem -Path $destination -filter *.jpg
过滤器是基于提供者
推荐阅读
- c# - 在 C# 中使用 LINQ 分组 - 索引超出范围
- java - Java 在 EDT 之外的自己的线程中绘制到图形?
- c# - 如何从asp.net C#中的动态字符串中读取结果标签?
- python - 获取 TypeError:'int' 对象不能从类继承中下标
- firebase - 我的网页未托管在 localhost firebase web 404 错误中
- r - 减少数据表的宽度,消除底部边框线,并使列名与列值居中/对齐
- r - 如何使用汇总来使用仅对其中一列进行的计算从多列中获取数据?
- build - 如何判断您正在查看哪种构建脚本
- r - 如何从R中的长字符串中顺序检索短字符串列表?
- ios - 为什么堆栈视图中的项目在 Swift 中占用太多空间