Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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
Powershell 无法检查扩展名为的文件_Powershell - Fatal编程技术网

Powershell 无法检查扩展名为的文件

Powershell 无法检查扩展名为的文件,powershell,Powershell,extension.txt文件包含文件扩展名列表,如*.txt、*.xlsx$a未获取扩展名(内容为$a),输出文件为空 当我处理这些数据时,数据即将到来,但我想在文本文件中保留扩展名 $ext = "C:\Users\xxxxx\Desktop\project1\my scripts\extension.txt" $a = Get-Content $ext $a $list = dir C:\Users\SyedNasiruddinS\Desktop\* -include $a | Sel

extension.txt文件包含文件扩展名列表,如*.txt、*.xlsx$a未获取扩展名(内容为$a),输出文件为空

当我处理这些数据时,数据即将到来,但我想在文本文件中保留扩展名

$ext = "C:\Users\xxxxx\Desktop\project1\my scripts\extension.txt"
$a = Get-Content $ext
$a

$list = dir C:\Users\SyedNasiruddinS\Desktop\* -include $a |  Select 
Directory,Fullname,Name,Length,CreationTime 
$list | Export-Csv "C:\Users\xxxx\Desktop\results.csv"

根据您的评论,您建议
$a
包含逗号分隔的扩展名列表,您可能需要执行以下操作:

$list = dir C:\Users\xxxx\Desktop\* -include *.txt, *.xlsx, *.exe |   Select Directory,Fullname,Name,Length,CreationTime 
$list | Export-Csv "C:\Users\xxxx\Desktop\results.csv"
说明:

-split','
将单个字符串拆分为一个字符串数组,然后-Include属性将其作为多个输入接受/处理


或者,更改extension.txt文件,使每个扩展名位于新行上(并删除,个字符)。

您可能希望开始接受一些答案…Get Content按tin上的说明执行。执行
测试路径$ext
,然后执行
记事本$ext
,以确保它存在并包含内容。因此,您的
$a
为空?从那里开始调试,例如,检查
Get Content
是否抛出拒绝访问错误。当我运行Get Content PS C:\windows\system32>$ext=“C:\Users\SyedNasiruddinS\Desktop\project1\my scripts\extension.txt”$a=Get Content$ext$a输出:*.txt,*.xlsxtension.txt contents.txt,*.xlsx,*.exe我想要的基本上是得到这些“.txt,*.xlsx,*.exe”,在代码中包含编译和执行的时间之后,那么我的答案应该对你有用。如果有,请接受。我的答案对您有用,因为
-Include
接受数组输入,并且使用
-split
会生成数组对象。此外,获取此错误获取内容:找不到与参数名称“split”匹配的参数。在第2行char:23+$a=Get Content$ext-split'、'和@SyedNasir,您需要使用头部而不是货物复制粘贴。
$ext = "extension.txt"
$a = ([IO.File]::ReadAllText($ext)) -split ','
$a

$list = dir * -include $a |  Select Directory,Fullname,Name,Length,CreationTime 
$list