Get the path where the batch file is located

   During development, it is often necessary to use batch processing to run some programs. The same is true for java programs, which often require the runtime root path. Hardcode a path always makes me feel uncomfortable. For example, when a java program is copied from one computer to another, the drive letter often changes. It is obviously troublesome to modify the path in bat before running it.
       Add a line of code cd /d %~dp0 at the beginning of the batch to truly do "write once, run everywhere". %0 is the path to the batch file itself, %~dp expands, d expands forward to the drive, and p expands backward to the path. For example, if your bat file is in e:/mybat/test.bat, then %0 is e:/mybat/test.bat, and %~dp0 is e:/mybat/.
        In addition, %i extracts the i-th command option, for example, %1 extracts the first option, and i can take a value from 1 to 9
        %~0: take the file name (name + extension)
        %~f0: take the full path
        %~ d0: take the drive name
        %~p0: take only the path (excluding the drive)
        %~n0: take only the file name
        %~x0: take only the file extension
        %~s0: take the abbreviated full path name
        %~a0: take the file attribute
        %~t0: Get the file creation time
        %~z0: Get the file size The
above options can be used in combination.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326455182&siteId=291194637