I want to get all the names in a directory as a comma separated string so that I can pass them as a parameter to a cmdlet.
How can I get all the file names in a directory as a comma separated string in Powershell?
一种方法是:
(dir | % { $_.basename }) -join ','
This should work:
(ls C:\PATH\TO\FOLDER | select -expandproperty name) -join ','
If there are subfolders in there that you want to avoid:
(ls C:\PATH\TO\FOLDER | ?{$_.PSIsContainer -eq $false} | select -expandproperty name) -join ','
Quickest/shortest way:
(ls).name -join ','
For specific folder-path:
(ls path\to\folder).name -join ','
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.