1

在 Windows 上使用 cmd,很容易通过 pushd 将驱动器号分配给 UNC 路径:

C:\Windows\> pushd \\server\share\path
Y:\> popd
C:\Windows\>

但是,我希望能够对本地路径执行相同的操作,因为它会缩短文件路径,并且我必须使用不支持具有很长路径的文件的命令。

这个想法如下G:,脚本中没有硬编码,因为它可以在另一台机器上使用。

subst G: .
pushd G:\
(other commands)
popd
subst G: /d

我试过pushd \\?\%CD%了,可惜没用……</p>

有没有人有这个魔术?

谢谢

4

2 回答 2

5

如果您在 Windows 7 上,则不必使用驱动器号。您可以改为创建符号链接。

要链接到文件夹,请使用:

cd <folder_you_want_the_link_in>
mklink /D \MyLinkedFolder \Folder\Folder\Folder\Folder\MyLinkedFolder
于 2011-11-23T08:02:32.953 回答
1

这是我不喜欢的临时解决方案,但尝试以编程方式查找从Z:pushd 开始的第一个可用驱动器号。我想它很容易失败。

call:find_first_available_drive
subst %drive% .
pushd %drive%\
(other commands)
popd
subst %drive% /d

:find_first_available_drive
@pushd Z: 2>NUL && popd || (set drive=Z:& goto:eof)
@pushd Y: 2>NUL && popd || (set drive=Y:& goto:eof)
@pushd X: 2>NUL && popd || (set drive=X:& goto:eof)
@pushd W: 2>NUL && popd || (set drive=W:& goto:eof)
@pushd V: 2>NUL && popd || (set drive=V:& goto:eof)
@pushd U: 2>NUL && popd || (set drive=U:& goto:eof)
@pushd T: 2>NUL && popd || (set drive=T:& goto:eof)
@pushd S: 2>NUL && popd || (set drive=S:& goto:eof)
@pushd R: 2>NUL && popd || (set drive=R:& goto:eof)
@pushd Q: 2>NUL && popd || (set drive=Q:& goto:eof)
@pushd P: 2>NUL && popd || (set drive=P:& goto:eof)
@pushd O: 2>NUL && popd || (set drive=O:& goto:eof)
@pushd N: 2>NUL && popd || (set drive=N:& goto:eof)
@pushd M: 2>NUL && popd || (set drive=M:& goto:eof)
@pushd L: 2>NUL && popd || (set drive=L:& goto:eof)
@pushd K: 2>NUL && popd || (set drive=K:& goto:eof)
@pushd J: 2>NUL && popd || (set drive=J:& goto:eof)
@pushd I: 2>NUL && popd || (set drive=I:& goto:eof)
@pushd H: 2>NUL && popd || (set drive=H:& goto:eof)
@pushd G: 2>NUL && popd || (set drive=G:& goto:eof)
@pushd F: 2>NUL && popd || (set drive=F:& goto:eof)
@pushd E: 2>NUL && popd || (set drive=E:& goto:eof)
@pushd D: 2>NUL && popd || (set drive=D:& goto:eof)
@pushd C: 2>NUL && popd || (set drive=C:& goto:eof)
@pushd B: 2>NUL && popd || (set drive=B:& goto:eof)
@pushd A: 2>NUL && popd || (set drive=A:& goto:eof)
@set drive=&goto:eof
于 2011-09-20T09:47:15.170 回答