【发布时间】:2016-08-22 00:46:36
【问题描述】:
我正在尝试使用 PowerShell 3.0 从许多文件名中删除空格。这是我正在使用的代码:
$Files = Get-ChildItem -Path "C:\PowershellTests\With_Space"
Copy-Item $Files.FullName -Destination C:\PowershellTests\Without_Space
Set-Location -Path C:\PowershellTests\Without_Space
Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace ' ','' }
例如:With_Space 目录有这些文件:
有线电视报告3413109.pdf 控制清单 3.txt 测试结果阶段2.doc
Without_Space 目录将需要上述文件名:
CableReport3413109.pdf 控制列表3.txt TestResultPhase 2.doc
目前,该脚本没有显示错误,但它仅将源文件复制到目标文件夹,但不会删除文件名中的空格。
【问题讨论】:
标签: powershell filenames