PowerTip: Read File with Backtick in Name

Summary: Read the content of a text file with a backtick ( ` ) in the name.

Hey, Scripting Guy! Question How can I use Windows PowerShell to read the content of a file that has a backtick ( ` ) in the file name?

Hey, Scripting Guy! Answer Use single quotation marks around the name when you supply the path to Get-Content, for example:

Get-Content 'c:\fso\a file with a `in the name.txt'

The following examples fail:

Get-Content "c:\fso\a file with a `in the name.txt"

Get-Content c:\fso\a file with a `in the name.txt

Comments (4)

  1. Escapist Character says:

    The following would also work:

    Get-Content a` file` with` a` “in` the` name.txt

    … but that way lies madness 🙂

  2. Larry Weiss says:

    Also throw in a -LiteralPath in front of the name in case of names like these consecutive backtick character file names

    For example:
    Get-Content -LiteralPath ‘“’
    Get-Content -LiteralPath ‘“`’

  3. MikeM says:

    For double quotation example, escaping the backtick with a backtick works as well – useful if variable expansion is needed within the file name.
    $n = "name"
    Get-Content "c:fsoa file with a “in the $n.txt"

  4. HicanNL says:

    MikeM’s comment indeed works fine. I used that on quite some occasion already!
    When you enter Get-Content in PowerShell and then type in the path to the file, you could just hit tab and it would "automagically" add the extra backtick!

Skip to main content