2
votes

Using Powershell, I am attempting to get a list of folders and files beginning at a certain level in the folder hierarchy like this:

Get-ChildItem -Path ./trunk -Recurse -include *.rpt

Because file names can contain spaces, I need to surround file name with single quotes so I can feed those file names into a Java program for processing:

java -cp . SomeJavaPgm (Get-ChildItem -Path ./tags -Recurse -include *.rpt)

How would I either define a PowerShell function and call it to delimit the output of the Get-ChildItem cmdlet with single quotes or pipeline the output of Get-ChildItem so that it would delimit the output with single quotes?

1

1 Answers

1
votes

An initial trial, as absolute path.

Get-Childitem -Path ./tags -Recurse -include *.rp | % {
$a = $_.fullname -replace '"', '""'; "'$a'"
}

Using the double aphostrophes

Get-Childitem -Path ./tags -Recurse -include *.rp | % {
    $a = $_.fullname -replace '"', '""'; "`"$a`""
}