批處理文件中的 %~d0

今天在批處理文件中 %~d0 ,莫名其妙, 答案是:


he magic variables %n contains the arguments used to invoke the file: %0 is the path to the bat-file itself, %1 is the first argument after, %2 is the second and so on.

Since the arguments are often file paths, there is some additional syntax to extract parts of the path. ~dis drive, ~p is the path (without drive), ~n is the file name. They can be combined so ~dp is drive+path.

%~dp0 is therefore pretty useful in a bat: it is the folder in which the executing bat file resides.

You can also get other kinds of meta info about the file: ~t is the timestamp, ~z is the size.

Look here for a reference for all command line commands. The tilde-magic codes are described underfor.



另外一網友補充

%~d0 gives you the drive letter of argument 0 (the script name), %~p0 the path.


參見網頁 http://stackoverflow.com/questions/112055/what-does-d0-mean-in-a-windows-batch-file

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章