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 に答える