Microsoft Windows batch file 中的%〜d0是什麼意思? batch file 可以寫小自動化安裝程式!
因為我們公司現在安裝 Microsoft Office 2019 是用 batch file 自動安裝。所以當你把 Office 2019 下載來到 C:\ 裡時,此時必須更改 " batch file 自動安裝 Office 2019 檔案路徑 " 和 " ProPlus2019.xml 檔案裡的路徑 " 。然後才能成功執行 batch file 自動安裝 。
Step 1: 更改 " batch file 自動安裝 Office 2019 檔案路徑 "
是的,您可以使用下面列出的其他快捷方式。 在您的命令中,〜d0表示第0個參數的驅動器號。〜擴展給定變量
d僅獲取驅動器號 。0是您要引用的參數
腳本所在的路徑(無驅動器):〜p0 。 腳本所在的驅動器:〜d0
Run 2:
D:\Workbench>batch c:\123\a.exe e:\abc\b.exe
~dp0= D:\Workbench\
~dp1= c:\123\
~dp2= e:\abc\
%~dp0 批次檔所在路徑,例如 C:\Program Files\Mozilla Firefox\ 或 UNC 路徑,例如 \\Server\Share\Program Files\Mozilla Firefox\
%~d0 批次檔所在磁碟代號,例如 C: 或 UNC 路徑的雙反斜線 \\
%~p0 批次檔所在路徑,不含磁碟代號,例如 \Program Files\Mozilla Firefox\ 或開頭不帶雙反斜線的 UNC 路徑,例如 Server\Share\Program Files\Mozilla Firefox\
%cd% 目前工作路徑,非根路徑時後面不帶反斜線,例如 C:\Program Files\Mozilla Firefox
------------------------------------------------------------------------------------
Add-1
剛剛為神秘的〜波浪號運算符找到了一些很好的參考。
%〜字符串稱為百分比波浪號運算符。 您可以在以下情況下找到它:%〜0。
:〜字符串稱為冒號波浪號運算符。 您可以找到它,例如%SOME_VAR:〜0,-1%。
ADD 2 - 1:12 PM 7/6/2018
%1-%9是指命令行參數。 如果它們不是有效的路徑值,則%〜dp1-%〜dp9都將擴展為與%〜dp0相同的值。 但是,如果它們是有效的路徑值,它們將擴展為自己的驅動程序/路徑值。
For example: (batch.bat)
@echo off
@echo ~dp0= %~dp0
@echo ~dp1= %~dp1
@echo ~dp2= %~dp2
@echo on
Run 1:
D:\Workbench>batch arg1 arg2
~dp0= D:\Workbench\
~dp1= D:\Workbench\
~dp2= D:\Workbench\
Run 2:
D:\Workbench>batch c:\123\a.exe e:\abc\b.exe
~dp0= D:\Workbench\
~dp1= c:\123\
~dp2= e:\abc\
它們是增強的變量替換。 它們修改批處理文件中使用的%N變量。 如果您要在Windows中進行批處理編程,那將非常有用。
%~I - expands %I removing any surrounding quotes ("")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH environment variable and expands %I to the
fully qualified name of the first one found. If the environment variable name is not
defined or the file is not found by the search, then this modifier expands to the
empty string
------------------------------------------------------------------------------------
由於第0個參數是腳本路徑,它將為您獲取路徑的驅動器號。 您可以使用以下快捷方式
%~1 - expands %1 removing any surrounding quotes (") %~f1 - expands %1 to a fully qualified path name %~d1 - expands %1 to a drive letter only %~p1 - expands %1 to a path only %~n1 - expands %1 to a file name only %~x1 - expands %1 to a file extension only %~s1 - expanded path contains short names only %~a1 - expands %1 to file attributes %~t1 - expands %1 to date/time of file %~z1 - expands %1 to size of file %~$PATH:1 - searches the directories listed in the PATH environment variable and expands %1 to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string %~dp1 - expands %1 to a drive letter and path only %~nx1 - expands %1 to a file name and extension only %~dp$PATH:1 - searches the directories listed in the PATH environment variable for %1 and expands to the drive letter and path of the first one found. %~ftza1 - expands %1 to a DIR like output line
留言
張貼留言