Batch command gets the current letter and current directory
%~D0 is the current disk character
%cd% is the current directory
You can print the test with Echo%cd%
The following example is the command line that compiles a program written by Visual Studio:
Copy Code code as follows:
@echo off
Set b=%cd%//Save current directory to parameter B, no spaces before and after 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 filename in double quotes.
Don't say much nonsense, just look at the example:
Copy Code code as follows:
@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
To get the top level of the current directory through batch processing
Copy Code code as follows:
@echo off
The current directory of If%cd%==%cd:~,3% echo is already the root directory of the%cd:~,1% disk! &goto End
Cd..
Set "bd=%cd%"
Cd..
Set "bbd=%cd%"
If "%bbd%" = = "%bd%" (Echo 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, in the first level directory, the second level directory, the third level directory, level fourth directory, are executed, the final result of the program is not very correct, here only give you a train of thought, and to the various levels of access to the directory method for reference only.