Home > Software design >  Powershell: Extract all file names from a directory and input them into a textbox
Powershell: Extract all file names from a directory and input them into a textbox

Time:10-06

I have a directory of pdf files all named differently for example

SOR001.pdf SOR002.pdf SOR003.pdf

is it possible to extract just the Basename and input that information to a textbox in visual studio. the format i am looking for would be like this (SOR001,SOR002,SOR003)

CodePudding user response:

To get a string like (SOR001,SOR002,SOR003):

'({0})' -f ((Get-ChildItem *.pdf).BaseName -join ',')

To get a string like ('SOR001','SOR002','SOR003'):

'({0})' -f ((Get-ChildItem *.pdf).BaseName.ForEach({ "'$_'" }) -join ',')

See also:

  • Related