There is still not the best support for trailing spaces in folder names on Windows. Most commands will work, when using UNC paths.
Windows command prompt
Creating a folder with a trailing space in its name:
md "\\?\C:\FolderWithTrailingSpace "
Renaming a folder with a trailing space in its name seems to require a workaround. Create a folder with the new name, move the content to it, delete the old folder:
md "C:\FolderWithoutTrailingSpace"
move "\\?\C:\FolderWithTrailingSpace \*" "C:\FolderWithoutTrailingSpace"
rd "\\?\C:\FolderWithTrailingSpace "
Deleting a folder with a trailing space in its name:
rd "\\?\C:\FolderWithTrailingSpace "
Windows PowerShell
Creating a folder with a trailing space in its name:
New-Item -Path "\\?\C:\FolderWithTrailingSpace " -Type Directory
Renaming a folder with a trailing space in its name:
Rename-Item -LiteralPath "\\?\C:\FolderWithTrailingSpace " -NewName "\\?\C:\RenamedFolderWithTrailingSpace "
Deleting a folder with a trailing space in its name:
Remove-Item -LiteralPath "\\?\C:\FolderWithTrailingSpace "
Workaround for cd
/Set-Location
In order to change your directory to a folder that contains a trailing space in its name, you can use a workaround with symbolic links. Create a symbolic link to the folder with a trailing space in its name using the mklink
command of an elevated Windows command prompt (not available in PS):
mklink /D "C:\FolderWithoutTrailingSpace" "\\?\C:\FolderWithTrailingSpace "
After that, you can use cd
in the command prompt or in PowerShell to switch to that directory:
cd C:\FolderWithoutTrailingSpace
Or use Set-Location
in PowerShell:
Set-Location -LiteralPath "C:\FolderWithoutTrailingSpace"