Batch command to get the current disk character and current directory
Current disc character:%~d0
Current path:% cd%
Current Execution Command Line:%0
Current bat file path:%~dp0
Current bat file short path:%~sdp0
Echo current disc character:%~d0 Echo current path:% cd% Echo currently executes the command line:% 0 Echo current bat file path:%~dp0 Echo current bat file short path:%~sdp0
The effect is shown in the figure below.
Print test can be done with echo% cd%.
Windows shortcuts cannot use relative paths. Relative paths can be obtained using batch files.
Set PA =% cd% assigns the current path to pa
Echo% pa% display PA variable
The following example is a command-line compilation program written by Visual Studio:
@echo off Set b=% cd%// Save the current directory to parameter B without spaces around 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, the path plus file name should be enclosed in double quotes.
Not much nonsense. Look at the examples directly.
@echo off Echo current disc character:%~d0 Echo current disc and path:%~dp0 The short file name format of the current disc character and path of echo:%~sdp0 Echo current batch full path:%~f0 Echo Current CMD Default Directory:% cd% pause
Upper level directories of current directories are fetched by batch processing
@echo off If% cd%==% cd:~, 3% echo current directory is already the root directory of% cd:~, 1% disk! & goto end cd.. set "bd=%cd%" cd.. set "bbd=%cd%" If "% bbd%" == "% bd%" (the upper echo directory is:% cd:~, the root directory of 1% disk! ) The directory of other call echo is "%% bd:% bbd%=%". :end pause
The above program I run and test, respectively, in the first level directory, the second level directory, the third level directory, the fourth level directory, are executed, the final results of the program are not correct, here only give you a train of thought, and access to directories at all levels for reference only.
A bat used before developpaer edition is convenient to delete the instructions in folders and copy their own instructions.
@echo off setlocal EnableDelayedExpansion del jb51.txt /s Del Description. htm/s Copy F: Edit jb51tools jb_down book cd% mkdir jb51.net del %0 | move *.* jb51.net
Code is relatively simple ah, do not understand the self-Baidu