Batch Bat command--get current drive letter and current directory and parent directory
Batch command gets current drive letter and current directory
%~D0 is the current drive letter
%cd% is the current directory
Can print test with echo%cd%
The following example is a command-line compilation of a program written by Visual Studio:
@echo off
Set b=%cd%//Save the current directory in parameter B with no spaces before and after the equals sign
C:
CD Program Files
cd Microsoft Visual Studio
CD Common
CD msdev98
CD bin
Msdev "%B%\TEST.DSP"/make "Test-win32 Release"/rebuild//(VC6.0)
Devenv "%b%\tool utility\tool Utility.sln"/rebuild//(VS2010)
Pause
Note: If the path contains spaces, you should enclose the path plus the file name in double quotation marks.
Source: http://blog.csdn.net/ylmmee/article/details/6735907
===============================================================
Nonsense not much to say, look directly at examples:
@echo off
Echo Current drive letter:%~d0
Echo Current drive letter and path:%~dp0
Echo Current drive letter and path short name format:%~sdp0
echo Current Batch full path:%~f0
echo Current cmd default directory:%cd%
Pause
Http://www.2cto.com/kf/201104/88450.html
===============================================================
To fetch the top level directory of the current directory by batch processing
@echo off
If%cd%==%cd:~,3% echo the current directory is already the root of the%cd:~,1% disk! &goto End
Cd..
Set "bd=%cd%"
Cd..
Set "bbd=%cd%"
If "%bbd%" = = "%bd%" (Echo Upper level directory is:%cd:~,1% disk root directory!)
else call echo Upper level directory is: "%%bd:%bbd%\=%%"
: End
Pause
P.S.
The above program I run and test, respectively, in the first level directory, the second level of the directory, the third level directory, the fourth level of the directory, are executed, the final result of the program is not correct, here only give you a thought, and all levels of the directory access method for reference only.
Source: HTTP://ZHIDAO.BAIDU.COM/LINK?URL=_3UFT92HVTRXF0VINIX4YVUEVQHQ448_97GLGBZAXN-8SWIOC3RKJGGGFPSXPI1H8UUKCV5YE0JNNA3CLQMHJQ
Batch Bat command--get current drive letter and current directory and parent directory