我将使用PowerShell(v.1)来复制与模式匹配的文件。文件命名约定为:
当我运行它时, "Copy-Item" 方法抱怨:
动态参数不能检索到 cmdlet。指定的通配符模式无效:Daily_Reviews[0001-0871].journal + Copy-Item <<<< $sourcefile $destination
该错误是由于文件名中的 "[" 和 "]" 引起的。当我删除左右括号时,它按预期工作。但是看起来 PowerShell 1 没有 -LiteralPath 标志,那么是否有另一种方法可以让带有括号的文件名在 PowerShell 1 中使用 Copy-Item?
Daily_Reviews[0001-0871].journal
Daily_Reviews[1002-9887].journal
[...]
当我运行它时, "Copy-Item" 方法抱怨:
动态参数不能检索到 cmdlet。指定的通配符模式无效:Daily_Reviews[0001-0871].journal + Copy-Item <<<< $sourcefile $destination
该错误是由于文件名中的 "[" 和 "]" 引起的。当我删除左右括号时,它按预期工作。但是看起来 PowerShell 1 没有 -LiteralPath 标志,那么是否有另一种方法可以让带有括号的文件名在 PowerShell 1 中使用 Copy-Item?
$source = "C:\Users\Tom\"
$destination ="C:\Users\Tom\Processed\"
if(-not(Test-Path $destination)){mkdir $destination | out-null}
ForEach ($sourcefile In $(Get-ChildItem $source | Where-Object { $_.Name -match "Daily_Reviews\[\d\d\d\d-\d\d\d\d\].journal" }))
{
Copy-Item $sourcefile $destination
}
$src = [Management.Automation.WildcardPattern]::Escape($sourcefile.FullName)
- lvr123