Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Powershell-包含$variable故障_Arrays_Powershell_Get Childitem - Fatal编程技术网

Arrays Powershell-包含$variable故障

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

为什么$arraychoices在这个gci中不起作用?。。但是如果我硬编码文件类型扩展名,它会吗

不起作用

$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。我怎么会错过呢。效果很好。谢谢你的时间,马蒂亚斯!