我正在尝试将目录中的文件列表保存到数组列表中,请您共享Windows PowerShell的代码段
我在c:\ temp下有2个文件
file1 : stack.zip
file2 : overflow.zip
需要将文件1和2存储在名为的数组中
$arrlst=['stack.zip','overflow.zip']
*set-Location -path "c:\temp"
fileslst=Get-children
$arrlst=[filelist]*
运行下面的内容将为您提供所需要的。
[System.Collections.ArrayList]$arrlst = @(
$(Get-ChildItem -File -Path 'C:\temp' | Select -ExpandProperty Name)
)
您需要执行Select -ExpandProperty Name
以确保Get-ChildItem
的唯一结果是包含扩展名(Name
)的文件名。