cmd中的%~dp0

cmd中的%~dp0

批处理中%~dp0是一个很好用的指令。其含义是当前所执行bat文件的路径。

那这几个字符中各自都代表什么含义呢。

%0,符合国际惯例,是指执行文件本身的路径。%1-%n表示后面跟的参数。

~,波浪号,表明后面可以跟修饰符,其中,d、p都是修饰符。d表示磁盘号,p表示路径。

所以,如果我们需要一个批处理文件的磁盘号,用%~d0即可获取到。

rem 进入批处理文件所在磁盘根目录
%~d0

rem 进入批处理文件所在目录
cd %~dp0

rem 上面2条语句可以合并成一条语句。。。:)
cd /d %~dp0

rem 执行某些必须进入特定目录才能执行的脚本,比如git pull
...
解释下面这段cmd文件的作用:CLS REM The following is required in all INSTALL.CMD files if exist c:\system.sav\util\SetVariables.cmd Call c:\system.sav\util\SetVariables.cmd set version=1.05 Set block=%~dp0 set errcodeinstallinstallinstallinstallinstallinstallinstall=0 CD /D "%block%" set Log_Folder=%~d0\programdata\HP\logs if not exist "%Log_Folder%" md "%Log_Folder%" set Install_Log=%Log_Folder%\HotkeyInstall.log REM Remove the REM from the next line if your component does not support Silent Install (Application Recovery) REM Erase /F /Q *.CVA REM Add the command-line to have your component to be installed properly Pushd src if exist "%~dp0src\Uninstall.cmd" ( call "%~dp0src\Uninstall.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodeinstall% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%" goto :END ) if exist "%~dp0src\InstallFusion.cmd" ( call "%~dp0src\InstallFusion.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodefusion% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%" goto :END ) if exist "%~dp0src\InstallDriver.cmd" ( call "%~dp0src\InstallDriver.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodedriver% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%"goto :END ) if exist "%~dp0src\InstallApp.cmd" ( call "%~dp0src\InstallApp.cmd" ) if %errorlevel% NEQ 0 ( echo. >> "%Install_log%" echo *exit /b %errcodeapp% >> "%Install_log%" echo. >> "%Install_log%" echo ^<^< %~f0 >> "%Install_log%" echo ^<^< %date% %time% >> "%Install_log%" echo. >> "%Install_log%" goto :END ) :END Popd REM Erase failure flag file when install succeeded. Most applications return zero to indicate success. ECHO %ERRORLEVEL% >> FAILURE.FLG IF %ERRORLEVEL% EQU 0 ERASE /F /Q FAILURE.FLG IF %ERRORLEVEL% EQU 3010 ERASE /F /Q FAILURE.FLG echo %date% %time% "Fusion=" %errcodefusion% >> %install_log% echo %date% %time% "Driver=" %errcodedriver% >> %install_log% echo %date% %time% "App=" %errcodeapp% >> %install_log% EXIT /B %ERRORLEVEL%
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值