2010-06-03 113 views

回答

0

测试:demo.bat

@echo off 
echo "Setting cpp" 
set cpp="C:\temp\lib.dll" 

echo "Calling JustGetPath" 
call :JustGetPath %cpp% 

echo "Returning result" 
echo %_RESULT% 

echo "Quitting" 
goto :eof 

:JustGetPath 
echo " +JustGetPath(%1)" 
set _RESULT=%~dp1 

echo " -JustGetPath()" 
GOTO :eof 

:eof 

输出以下运行时:

"Setting cpp" 
"Calling JustGetPath" 
" +JustGetPath(C:\temp\lib.dll)" 
" -JustGetPath()" 
"Returning result" 
C:\temp\ 
"Quitting" 

参见:http://ss64.com/nt/call.html

1

可以使用for命令,就像这样:

set cpp="C:\temp\lib.dll" 

:: Print the full path and file name: 
echo %cpp% 

:: Print just the path: 
for %%P in (%cpp%) do echo %%~dpP 
+0

我试过这个没有成功 - 无可否认,它是在Linux上的WINE,所以也许解释器还没有完全兼容微软Windows ... – 2010-06-03 15:17:26

+0

@PP:嗯,这个工作在我的XP,Windows 7,Server 2003上和Server 2008盒子。 – 2010-06-03 16:29:23

+0

适用于win7,我喜欢这个,但是学习CALL的方式对我来说是一个启示,所以我给它V – yoshco 2010-06-06 08:29:33