如何在命令提示符下使用 CD 命令更改为仅以空格命名的文件夹? [英] How can use CD command in command prompt to change to a folder named only with a space?

查看:46
本文介绍了如何在命令提示符下使用 CD 命令更改为仅以空格命名的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个批处理文件,我想进入一个仅以空格命名的目录,例如:

"D:/Drive/"

我尝试了 "",'',"/""%20" 但什么都没有工作.

我该怎么做?

解决方案

我能够使用 完全限定路径 by mkdir "\\?\D:\ ".但是,资源管理器或 cmd 都无法访问该文件夹

在 Windows 资源管理器中,尽管它实际上已经进入了子文件夹,但进入文件夹始终显示父文件夹的内容,因此您无法对该内容进行任何操作,并且资源管理器的标题栏变为空白,因为它显示了文件夹名称.在 cmd cd 中,除非您使用 SomethingDark 的答案 中的技巧,否则将保留在父文件夹中.您可能需要删除或重命名它

很遗憾,我还没有找到重命名文件夹的方法.但是用相同的路径删除它很容易

rmdir "\\?\D:\ "

普通路径也可以,但你最后总是需要一个斜线

mkdir ".\";rmdir ".\";

可以在该文件夹中存储文件

D:\>>.\\a.txt";回声ABCD:\>输入.\\a.txt";美国广播公司

文件夹中有一些内容后,资源管理器现在可以正常输入了.不幸的是 cmd 仍然无法更改为它.完全限定的路径可能会有所帮助,不幸的是 cmd 不支持它.但是PowerShell 确实支持它并且可以像资源管理器一样输入它

<前>PS D:\>猫'.\\a.txt'美国广播公司PS D:\>cd '.\'cd : 指定路径 D:\ 处的对象不存在.在行:1 字符:1+ cd '.\'+ ~~~~~~~~~+ CategoryInfo : InvalidArgument: (:) [Set-Location], PSArgumentException+ FullQualifiedErrorId:参数,Microsoft.PowerShell.Commands.SetLocationCommandPS D:\>cd '\\?\D:\'PS Microsoft.PowerShell.Core\FileSystem::\\?\D:\ >目录目录:\\?\D:\模式 LastWriteTime 长度 名称---- ------------- ------ -----a---- 8/23/2018 3:39 PM 5 a.txt

遗憾的是,一旦您进入,您就无法使用 cd .. 返回,您必须再次使用完全限定路径

<前>PS Microsoft.PowerShell.Core\FileSystem::\\?\D:\ >光盘..cd : 找不到路径 '\\?\D:' 因为它不存在.在行:1 字符:1+ 光盘 ..+ ~~~~~+ CategoryInfo : ObjectNotFound: (\\?\D::String) [Set-Location], ItemNotFoundException+ FullQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommandPS Microsoft.PowerShell.Core\FileSystem::\\?\D:\ >echo `"$(pwd)`""Microsoft.PowerShell.Core\FileSystem::\\?\D:\"

I'm creating a Batch-file and I want go into a directory named only with whitespace e.g.:

"D:/Drive/ "

I tried with "",'',"/" and "%20" but nothing worked.

How can I do this?

解决方案

I was able to create the directory with a fully-qualified path by mkdir "\\?\D:\ ". However that folder can't be accessed by either Explorer or cmd

In Windows Explorer entering the folder always show the parent folder's content although it has actually entered the subfolder, therefore you can't do anything with that content, and Explorer's title bar becomes blank since it displays the folder name. In cmd cd stays on the parent folder unless you use the trick in SomethingDark's answer. You probably need to remove or rename it

Sad to say I've yet to find a way to rename the folder. However it's easy to delete it with the same path

rmdir "\\?\D:\ "

A normal path will also work but you always need a slash at the end

mkdir ".\ \"
rmdir ".\ \"

It's possible to store files in that folder

D:\>>".\ \a.txt" echo abc

D:\>type ".\ \a.txt"
abc

Once you have some content in the folder Explorer can now enter it normally. Unfortunately cmd still can't change into it. A fully-qualified path may help, unluckily cmd doesn't support it. However PowerShell does support it and can enter it like Explorer

PS D:\> cat '.\ \a.txt'
abc
PS D:\> cd '.\ \'
cd : An object at the specified path D:\  does not exist.
At line:1 char:1
+ cd '.\ \'
+ ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], PSArgumentException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.SetLocationCommand

PS D:\> cd '\\?\D:\ \'
PS Microsoft.PowerShell.Core\FileSystem::\\?\D:\ > dir


    Directory: \\?\D:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        8/23/2018   3:39 PM              5 a.txt

Sadly once you entered you can't use cd .. to go back and you must use fully-qualified path again

PS Microsoft.PowerShell.Core\FileSystem::\\?\D:\ > cd ..
cd : Cannot find path '\\?\D:' because it does not exist.
At line:1 char:1
+ cd ..
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (\\?\D::String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS Microsoft.PowerShell.Core\FileSystem::\\?\D:\ > echo `"$(pwd)`"
"Microsoft.PowerShell.Core\FileSystem::\\?\D:\ "

这篇关于如何在命令提示符下使用 CD 命令更改为仅以空格命名的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆