简体   繁体   English

Powershell -include $variable 问题

[英]Powershell -include $variable trouble

Why doesn't $arraychoices work in this gci?.. But if I hard code the file type extension in it does?为什么 $arraychoices 在这个 gci 中不起作用?..但是如果我硬编码文件类型扩展名呢?

Doesn't work不起作用

$filetypes = @()
$filetypes += '*.pdf'
$filetypes += '*.txt'
$ftc = $filetypes
$arraychoices = "('$($ftc -join "','")')"

$fr = Get-ChildItem C:\backuptest **-include $arraychoices** -Recurse 
$files = $fr.fullname
$files

Harcode Works?硬编码作品?

Get-ChildItem C:\backuptest **-include ('*.pdf','*.txt')** -Recurse 

What am I missing?我错过了什么? Im my above example.我上面的例子。 Im using check boxes for file type extensions, so the hard code method isn't an option.我使用文件类型扩展名的复选框,所以硬编码方法不是一种选择。

Any help is appreciated.任何帮助表示赞赏。 TIA TIA

$filetypes is already an array of strings - pass it directly to the -Include parameter: $filetypes已经是一个字符串数组- 将它直接传递给-Include参数:

$filetypes = @()
$filetypes += '*.pdf'
$filetypes += '*.txt'

Get-ChildItem -Include $filetypes ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM