从 NT shell 脚本中,我需要能够判断目标路径是否位于本地驱动器上(例如C:\
or D:\
)或在远程/映射驱动器上(或者\\UNC\path
或映射的驱动器盘符,例如Z:
)... 有什么建议么?
@echo off
goto main
:isremote
setlocal
set _isremote=0
if "%~d1"=="\\" (set _isremote=1) else (
(>nul 2>&1 net use "%~d1") && set _isremote=1
)
endlocal&set isremote=%_isremote%&goto :EOF
:test
call :isremote "%~1"
echo %isremote% == %~1
@goto :EOF
:main
call :test c:
call :test c:\
call :test c:\windows
call :test \\foo
call :test \\foo\
call :test \\foo\bar
call :test \\foo\bar\baz
call :test z:
call :test z:\
call :test z:\temp
在我的系统上,其中 z: 是映射驱动器,我得到:
0 == c:
0 == c:\
0 == c:\windows
1 == \\foo
1 == \\foo\
1 == \\foo\bar
1 == \\foo\bar\baz
1 == z:
1 == z:\
1 == z:\temp
注意:NT6+ 上的 UNC 符号链接可能会失败
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)