Storing Directory Folder Names Into Array Powershell Storing Directory Folder Names Into Array Powershell powershell powershell

Storing Directory Folder Names Into Array Powershell


Here's another option using a pipeline:

$arr = Get-ChildItem \\QNAP\wpbackup |        Where-Object {$_.PSIsContainer} |        Foreach-Object {$_.Name}


$array = (dir *.txt).FullName

$array is now a list of paths for all text files in the directory.


For completeness, and readability:

This get all files in "somefolder" starting with 'F' to an array.

$FileNames = Get-ChildItem -Path '.\somefolder\' -Name 'F*' -File

This gets all directories of current directory:

$FileNames = Get-ChildItem -Path '.\' -Directory