As I was not able to reproduce the solution of the accepted answer, and other answers did not help either (except the 8.3 naming workaround), I want to share some methods that I already included in this answer:
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"
mkdir
andrmdir
commands built intocmd.exe
. Is it possible the name contains other characters? E.g., are those double quotes part of the name or is it possible those spaces aren't spaces and displaying as spaces?mv.exe
from GnuWin32 or Cygwin. On Windows 10, usewsl mv
from Windows Subsystem for Linux.