为什么$ 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 ...

关于arrays - Powershell-包括$ variable麻烦,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63870963/

10-09 20:52