我正在尝试将文件列表保存在目录到数组列表中,能否请您共享Windows PowerShell的代码段。
我在c:\ temp下有2个文件
文件1:stack.zip
文件2:overflow.zip
需要将file1和file2存储在名为的数组中
$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
)。
关于powershell - 将目录中的文件列表添加到数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58297648/