Add quote in directory list in output file RRS feed

  • Question

  • I am executing this script to have a list of all directories and sub-directories located in the appdata of a user profile.  My script works like I want but, because some directories, many directories have space in name, I would to add quote at the beginning of each output line and a quote at the end of each line.

    Now I am getting:

    C:\users\xyz\appdata\dir 1

    C:\users\xyz\appdata\dir 2

    C:\users\xyz\appdata\dir 3

    I would like to have:

    “C:\users\xyz\appdata\dir 1”

    “C:\users\xyz\appdata\dir 2”

    “C:\users\xyz\appdata\dir 3”

    Here my script:

    $ExcludeDirList = Get-ChildItem -Path “c:\users\xyz\appdata” -Recurse -Directory -Force -ErrorAction SilentlyContinue |  Select-Object  -expandproperty FullName

    Out-File -FilePath ./list.txt -Append -InputObject $ExcludeDirList

    Monday, February 25, 2019 12:08 AM

All replies

  • Please do not post colorized text or code. For code use the code posting tool provided on the edit bar of the post editor. Thanks.

    You could use a calculated property to add unnecessary extra double quotes to the output ....  like this:

    Get-ChildItem 'c:\users\xyz\appdata' -Recurse -Directory -Force -ErrorAction SilentlyContinue |  
        Select-Object  @{Name='QuotedFullName';Expression={"""$($_.FullName)"""}} |
            Select-Object -ExpandProperty QuotedFullName |
                Out-File -FilePath "./list.txt" -Append

    ... just because I'm curious - whatfor do you need these extra quotes?

    Edit:   .... another trick could be to "miss-use" Export-CSV ...

    Get-ChildItem 'c:\users\xyz\appdata' -Recurse -Directory -Force -ErrorAction SilentlyContinue |
        Select-Object -Property Fullname |
            Export-Csv -Path './list.csv' -NoTypeInformation -Append

    Live long and prosper!


    Monday, February 25, 2019 12:25 AM
  • Note, inside a quoted string, you can include quote characters by doubling them. For example:


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Monday, February 25, 2019 12:42 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Monday, February 25, 2019 2:00 AM