dir usage
- dir /b *.java
- list all files end with .java in current directory in simple format
- dir /b/s *.java
- list all files end with .java in current directory recursively in simple format
for usage
- for [/d][/r] %i in (set) do command [command-parameters]
- %i : variable, case sensitive
- set : file list. ex : (file.txt file2.txt), (*.txt)
- /d : similar to 1. but (set) is not file list, is a directory list
- /r : do same "for work" in every sub directory of current place
- for /L %variable in (start,step,end) do command [command-parameters]
- numerical iteration. ex. (1,1,5) = (1 2 3 4 5), (5,-1,1) = (5 4 3 2 1)
- FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
- FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
- FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
- FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
- FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
- FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]
- eol=c : end of line charactor
- skip=n : skip n lines
- delims=xxx : delims charactor list
- tokens=x,y,m-n :
- 指定每一行的哪些文字串應該被傳到 for 的內部以用來進行每一個重複操作。
- 這會導致額外的變數名稱被配置。
- m-n 格式代表一個範圍,指定了第 m 個到第 n 個字串項。
- 如果在 tokens= 字串的最後一個字元是星號,則會配置一個額外的變數來接收最後一個字串項被分析後的其他文字。
- usebackq
- 指定新語義開始作用。
- `反括號`的字串會被當作命令來執行
- '單引號'字串是純文字字串
- 此外還允許使用"雙引號"來引用在 filenameset 內的檔名。
example :
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k
%IMPORTENT%
when using a variable in batch file, the usage is %%v not %v
沒有留言:
張貼留言