How to Escape Spaces in File Paths on the Windows Command Line


Command Prompt window on Windows 10

Command-line environments like the Home windows Command Prompt and PowerShell use spaces to independent commands and arguments—but file and folder names can also incorporate areas. To specify a file route with a area within it, you are going to have to have to “escape” it.

Command Line 101: Why You Have to Escape Spaces

“Escaping” a character modifications its indicating. For case in point, escaping a house will lead to the shell to deal with it like a typical room character somewhat than a unique character that separates command-line arguments.

For instance, let’s say you have a textual content file that you want to see the contents of. You can do that with the style command. Assuming the textual content file is at C:TestFile.txt, the following command in Command Prompt will demonstrate its contents:

type C:TestFile.txt

Terrific. Now, what if you have the similar file at C:Exam FolderTest File.txt? If you attempt functioning the under command, it won’t work—those areas in the file path are acquiring in the way.

kind C:Test FolderTest File.txt

The command line thinks you’re hoping to seem for a file called C:Examination and says it “cannot obtain the route specified.”

A few Means to Escape Areas on Home windows

There are three distinct techniques you can escape file paths on Windows:

  • By enclosing the route (or parts of it) in double quotation marks ( ” ).
  • By including a caret character ( ^ ) right before each individual house. (This only functions in Command Prompt/CMD, and it doesn’t seem to perform with every command.)
  • By including a grave accent character ( ` ) in advance of each individual room. (This only operates in PowerShell, but it normally will work.)

We’ll present you how to use every process.

Enclose the Path in Quotation Marks ( ” )

The normal way to guarantee Home windows treats a file route effectively is to enclose it in double quotation mark ( ” ) people. For instance, with our sample command higher than, we’d just run the following instead:

form "C:Test FolderTest File.txt"

You can essentially enclose areas of the path in quotation marks if you like. For instance, let us say you experienced a file named File.txt in that folder. You could operate the next:

type C:"Test Folder"File.txt

Even so, that is not necessary—in most scenarios, you can just use quotation marks close to the complete route.

This solution will work both equally in the traditional Command Prompt (CMD) setting and in Home windows PowerShell.

At times: Use the Caret Character to Escape Areas ( ^ )

In the Command Prompt, the caret character ( ^ ) will let you escape spaces—in theory. Just add it right before each house in the file name. (You will uncover this character in the number row on your keyboard. To sort the caret character, push Change+6.)

Here’s the trouble: Though this should really operate, and it does often, it doesn’t get the job done all the time. The Command Prompt’s dealing with of this character is bizarre.

For illustration, with our sample command, you’d run the adhering to, and it wouldn’t get the job done:

kind C:Examination^ FolderTest^ File.txt

On the other hand, if we test opening our file immediately by typing its route into the Command Prompt, we can see that the caret character escapes the spaces properly:

C:Examination^ FolderTest^ File.txt

So when does it do the job? Nicely, based on our research, it looks to work with some apps and not other folks. Your mileage may well differ based on the command you are utilizing. The Command Prompt’s handling of this character is odd. Give it a test with whatever command you are making use of, if you are interested—it might or could not get the job done.

For consistency, we propose you stick with double quotes in the Command Prompt—or swap to PowerShell and use the grave accent technique below.

PowerShell: Use the Grave Accent Character ( ` )

PowerShell uses the grave accent ( ` ) character as its escape character. Just add it ahead of every single space in the file identify. (You’ll discover this character earlier mentioned the Tab crucial and down below the Esc vital on your keyboard.)

sort C:Test` FolderTest` File.txt

Each individual grave accent character tells PowerShell to escape the next character.

Take note that this only will work in the PowerShell environment. You are going to have to use the caret character in Command Prompt.


If you’re common with UNIX-like working methods like Linux and macOS, you might be used to making use of the backslash ( ) character before a place to escape it. Home windows works by using this for usual file paths, so it does not work—-the caret ( ^ ) and grave accent ( ` ) figures are the Home windows edition of backslash, relying on which command-line shell you’re using.

Exit mobile version