2011-09-20 6 views
1

、のpushdとUNCパスにドライブ文字を割り当てることは簡単です:cmd - 利用可能なドライブ文字をローカルパスに一時的に割り当てることはできますか? Windows上のCMDを使用して

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

それが短くなりますので、私はローカルパスと同じことを行うことができるようにしたいと思いますが非常に長いパスを持つファイルをサポートしていないコマンドを使用する必要があります。それは別のマシン上で使用される可能性があるため

アイデアは、スクリプトにハードG:せずに次のようです。私はpushd \\?\%CD%を試してみましたが、残念ながら、それは動作しません

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

...

は、誰もがそのための魔法のトリックを持っていますか?

は、これは私が嫌いな一時的な解決策ですが、プログラムでのpushdが行うように Z:から始まる最初の使用可能なドライブ文字を見つけようとします

+0

:フォルダの使用にリンクする

? 'net use'だけを使って考えましたか? – tenfour

+0

@tenour:一部のアプリケーションではサポートされていません(バッファが小さすぎます)。 'net use'はsubstのようなドライブ文字を必要とします。 – Benoit

+0

私にとってうまくいったことの1つは、260文字のMAX_PATHにはるかに少ない8.3のパスを使用することです。 – ewall

答えて

5

Windows 7の場合は、ドライブレターを使用する必要はありません。代わりにシンボリックリンクを作成することができます。本当に長いパスと間違って何

cd <folder_you_want_the_link_in> 
mklink /D \MyLinkedFolder \Folder\Folder\Folder\Folder\MyLinkedFolder 
0

ありがとうございます。私はそれが簡単に失敗することができると思います。

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 
関連する問題