[英]I want to import a csv to use as filter in the powershels gci command
I have a csv file with extension and description.我有一个带有扩展名和描述的 csv 文件。 I want to import that file and use it as the filter parameter in a gci command.我想导入该文件并将其用作 gci 命令中的过滤器参数。 But I get no results.但我没有得到任何结果。
I expect to get a list of the jpg files but get no results.我希望获得 jpg 文件的列表,但没有得到任何结果。
$extensions=Import-CSV -Path c:\scripts\Media-extension-foto.csv
#$extensions=Import-CSV -Path c:\scripts\Media-extension-foto.csv -header extension
$extensions.extension
$src = "c:\scripts\"
#gci c:\scripts\ -Include $Extensions.extension #-Force -recurse
#gci c:\scripts\ -filter $Extensions.extension #-Force -recurse
gci c:\scripts\|where{$_ -like $extensions.extension}`
my csv file looks like this (just made a small file for testing)我的 csv 文件看起来像这样(只是制作了一个小文件用于测试)
extension,"description"
*.JPEG,JPEG Image
*.JPF,JPEG 2000 Image
*.JPG,JPEG Image
*.JPG_LARGE,Twitter Large JPEG Image
There are jpg files in that folder:该文件夹中有jpg文件:
Directory: C:\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 23/11/2022 11:02 509592 nieuw9754560_02-10.jpg
-a--- 23/11/2022 11:02 576486 nieuw9754560_02-15.jpg
-a--- 23/11/2022 11:02 641802 nieuw9754560_02-20.jpg
-a--- 23/11/2022 11:01 705702 nieuw9754560_02-25.jpg
-a--- 23/11/2022 11:01 763249 nieuw9754560_02-30.jpg
I've just tested this - I think all you're missing is changing the $_ to $_.Extension for the Get-ChildItem, on the last line.我刚刚对此进行了测试 - 我认为您所缺少的只是在最后一行将 Get-ChildItem 的 $_ 更改为 $_.Extension。
Hope that helps.希望有所帮助。
Doesn't directly fix the code but here's another way of getting the result using foreach
to iterate through each extension in the array:不直接修复代码,但这是使用foreach
遍历数组中的每个扩展名获取结果的另一种方法:
foreach($e in $extensions.extension) {
gci c:\scripts\ | where {$_ -like $e}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.