我需要对以下 Powershell 脚本进行更改,但我有一段时间让生成的文件写入不同的路径......让我们称之为$destPath。
考虑:
Get-ChildItem $sourcePath | % { [system.io.file]::Move($_.fullname, ($_.FullName -replace '\[|\]|-|,|\(|\)', '') ) }
根据我对move语法的理解,$_.fullname是我的原始文件,并且$_.FullName -replace...是新文件名。但是,当我尝试使用时,$destPath.FullName -replace我得到一个空文件名不合法的错误。显然,Powershell 没有将其识别为move命令的有效路径名。
我错过了什么?