将目录中的文件列表添加到数组列表中

问题描述 投票:1回答:2

我正在尝试将文件列表保存在目录到数组列表中,请您共享Windows PowerShell的代码段。

我在c:\ temp下有2个文件

file1:stack.zipfile2:overflow.zip

需要将文件1和文件2存储在名为数组中的>]

$arrlst = ['stack.zip','overflow.zip']
Set-Location -Path "c:\temp"
fileslst = Get-children
$arrlst = [filelist]

我正在尝试将文件列表保存在目录到数组列表中,请您共享Windows PowerShell的代码段。我在c:\ temp file1下有2个文件:stack.zip file2:overflow.zip ...

powershell get-childitem
2个回答
2
投票

运行下面的内容将为您提供所需要的。


0
投票
$scriptpath='c:\temp'
$fileNames = Get-ChildItem -File -Path $scriptPath -Recurse -Include *.zip | Select -ExpandProperty Name

foreach ($vinodh in $fileNames)
{
write-host $vinodh

}
© www.soinside.com 2019 - 2024. All rights reserved.