Arrays Powershell-包含$variable故障
为什么$arraychoices在这个gci中不起作用?。。但是如果我硬编码文件类型扩展名,它会吗 不起作用Arrays Powershell-包含$variable故障,arrays,powershell,get-childitem,Arrays,Powershell,Get Childitem,为什么$arraychoices在这个gci中不起作用?。。但是如果我硬编码文件类型扩展名,它会吗 不起作用 $filetypes = @() $filetypes += '*.pdf' $filetypes += '*.txt' $ftc = $filetypes $arraychoices = "('$($ftc -join "','")')" $fr = Get-ChildItem C:\backuptest **-include $arraych
$filetypes = @()
$filetypes += '*.pdf'
$filetypes += '*.txt'
$ftc = $filetypes
$arraychoices = "('$($ftc -join "','")')"
$fr = Get-ChildItem C:\backuptest **-include $arraychoices** -Recurse
$files = $fr.fullname
$files
Harcode有效吗
Get-ChildItem C:\backuptest **-include ('*.pdf','*.txt')** -Recurse
我错过了什么?我就是我上面的例子。我正在为文件类型扩展名使用复选框,因此硬代码方法不是一个选项
感谢您的帮助。
TIA
$filetypes
已经是一个字符串数组-将其直接传递给-Include
参数:
$filetypes = @()
$filetypes += '*.pdf'
$filetypes += '*.txt'
Get-ChildItem -Include $filetypes ...
字符串
'a,b'
与字符串数组'a','b'
之间存在差异。完全跳过$ftc
/$arraychoices
步骤:获取ChildItem-包括$filetypes
O wow。我怎么会错过呢。效果很好。谢谢你的时间,马蒂亚斯!