简体   繁体   中英

How to use Set-Location on a folder with trailing spaces in PowerShell?

I have mounted a linux shared folder. In the folder, there is a sub-folder . \ . \ (dot space) which I need to access. With the command prompt I can access it using the 8dot3 notation of short names, but I need to access it with PowerShell.

Set-Location and cd will throw an error on paths with folder names with trailing spaces (path does not exist).

Windows still does not have the best support for folder names with trailing spaces. You can use a workaround with symbolic links. Create a symbolic link to the folder that contains a trailing space in its name using the mklink command of an elevated Windows command prompt (not available in PS as it is a command and not a tool) and define your path as a UNC path:

mklink /D C:\MyLink "\\?\C:\path\to\folder\. "

After that you can do:

cd C:\MyLink

or:

Set-Location -LiteralPath C:\MyLink

in PowerShell to work from your directory that has a trailing space in its name.

You can read more on operations with folder names containing trailing spaces in my answer here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM