常用的批处理文件技巧。或者说诡异的批处理文件。
1      新建空文件:
      第二种方法使用了更少的语句达到相同的效果。
TYPE NUL > NEW_EMPTY_FILE_NAME

CD. > NEW_EMPTY_FILE_NAME

2      for中的绑定:
 Loop

输出如下:
This is the exact FOR loop we're going to run:
FOR %%A IN (1 2 3) DO SET VAR=%VAR%%%A
Note how the FOR command on the prompt changes with each iteration:

D:\>SET VAR
Environment variable VAR not defined

D:\>FOR %A IN (1 2 3) DO SET VAR=%A

D:\>SET VAR=1

D:\>SET VAR=2

D:\>SET VAR=3

D:\>SET VAR
VAR=3

Press any key to continue . . .
当press 3次后可以发现VAR的值变成了333.
 Loop

This is the exact FOR loop we're going to run:
FOR %%A IN (1 2 3) DO SET VAR=!VAR!%%A
Note that the FOR command on the prompt does NOT change with each iteration:

D:\>SET VAR
Environment variable VAR not defined

D:\>FOR %A IN (1 2 3) DO SET VAR=!VAR!%A

D:\>SET VAR=!VAR!1

D:\>SET VAR=!VAR!2

D:\>SET VAR=!VAR!3

D:\>SET VAR
VAR=!VAR!3

Press any key to continue . . .


3     大小写转换:

:EOF


4      Call规则
%~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 - changes the meaning of n and x options to reference the short name instead
%~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
 
The modifiers can be combined to get compound results:
 
%~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
 
In the above examples %1 and PATH can be replaced by other valid values.
The %~ syntax is terminated by a valid argument number.
The %~ modifiers may not be used with %*

5      shift 遍历输入参数
)

相关文章: