最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】Windows Batch File test

Windows crifan 2763浏览 0评论

@echo off
:: just test batch
REM just test batch
echo following is just the windows Batch File test …
echo ————————1. misc test ————————
echo refer http://www.computerhope.com/batch.htm
echo (1)
echo current date:
echo %DATE%
echo (2)
echo this is the test batch, you need press a key for following is a pause
pause

::echo follow use cls to clear your screen of all previous text and only return the prompt
::cls

::echo test run windows application: calc(calulator)
::start calc
::START calc

echo ————————2. parameters test————————
echo refer http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true
echo (1)
echo all parameters  :%*
echo parameter 0  :%0
echo parameter 1  :%1
echo parameter 2  :%2
echo (2)
echo following 0 can be 1/2/…, corresponding to parameter 1/2/…
echo original file name :%0
echo removes any surrounding quotation marks ("") :%~0
echo fully qualified path name :%~f0
echo drive letter  :%~d0
echo drive path  :%~p0
echo file name  :%~n0
echo file extension  :%~x0
echo contains short names only:%~s0
echo file attributes:%~a0
echo date and time of file:%~t0
echo size of file:%~z0
echo Searches the directories listed in the PATH environment variable and expands "'%'0"
echo to the fully qualified name of the first one found. If the environment variable name is not defined
echo or the file is not found, this modifier expands to the empty string:%~$PATH:0
echo (3)
echo drive letter and path:%~dp0
echo drive letter path file name file extention, equal full file name:%~dpnx0

echo ————————3. extract sub string test————————
echo refer http://ss64.com/nt/syntax-substring.html
::syntax:
::
::Variables: extract part of a variable (substring)
::It is possible to retrieve specific characters from a string variable.
::
::Syntax
::      %variable:~num_chars_to_skip%
::      %variable:~num_chars_to_skip,num_chars_to_keep%
::
::This can include negative numbers:
::
::      %variable:~num_chars_to_skip, -num_chars_to_skip%
::      %variable:~-num_chars_to_skip,num_chars_to_keep%
:: NOTE: A negative number will count backwards from the end of the string
echo (1)
set filename=%~f0
echo file name:%filename%
echo remove the first 5 char:%filename:~5%
echo only retain the 3-6 char:%filename:~2,4%
echo only retain the last 4 char:%filename:~-4%
echo skip the last 5 char, retain 3 char, that is, remain the last 2-5 char :%filename:~-5,3%

echo ————————4. output special char————————
echo refer http://ss64.com/nt/syntax-esc.html
echo output percent char:%%
echo tilde:~
echo When piping or redirecting any of these charcters you should prefix with the escape character:^  ^&  ^|  ^>  ^<  ^^

转载请注明:在路上 » 【整理】Windows Batch File test

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.180 seconds, using 22.17MB memory