{"id":726,"date":"2015-05-01T08:43:47","date_gmt":"2015-05-01T00:43:47","guid":{"rendered":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/?p=726"},"modified":"2023-09-05T21:13:43","modified_gmt":"2023-09-05T13:13:43","slug":"windows-%e6%89%b9%e6%ac%a1%e6%aa%94%e8%99%95%e7%90%86%e6%95%99%e5%ad%b8","status":"publish","type":"post","link":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/archives\/726","title":{"rendered":"Windows Batch Scripting \u6559\u5b78"},"content":{"rendered":"<h2>\u6559\u5b78\u7db2\u7ad9\uff1a<\/h2>\n<ul>\n<li>BAT\uff1a\u6279\u8655\u7406\u6559\u5b78\uff08\u4e0a\uff09 @ \u96c5\u75de\u5c0f\u5b85:: \u96a8\u610f\u7aa9Xuite\u65e5\u8a8c<\/li>\n<li>BAT\uff1a\u6279\u8655\u7406\u6559\u5b78\uff08\u4e0b\uff09 @ \u96c5\u75de\u5c0f\u5b85:: \u96a8\u610f\u7aa9Xuite\u65e5\u8a8c<\/li>\n<li><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting\" target=\"_blank\" rel=\"noopener\">Wikibooks Windows Batch Scripting<\/a><\/li>\n<\/ul>\n<h2>\u7cfb\u7d71\u5167\u5efa\u6307\u4ee4\uff1a<\/h2>\n<table border=\"1\">\n<tbody>\n<tr>\n<th>Command<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#ASSOC\">ASSOC<\/a><\/td>\n<td>Associates an extension with a file type (FTYPE).<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#BREAK\">BREAK<\/a><\/td>\n<td>Sets or clears extended CTRL+C checking.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#CALL\">CALL<\/a><\/td>\n<td>Calls one batch program from another.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#CD\">CD<\/a>, <a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#CHDIR\">CHDIR<\/a><\/td>\n<td>Displays or sets the current directory.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#CHCP\">CHCP<\/a><\/td>\n<td>Displays or sets the active code page number.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#CLS\">CLS<\/a><\/td>\n<td>Clears the screen.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#COLOR\">COLOR<\/a><\/td>\n<td>Sets the console foreground and background colors.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#COPY\">COPY<\/a><\/td>\n<td>Copies files.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#DATE\">DATE<\/a><\/td>\n<td>Displays and sets the system date.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#DEL\">DEL<\/a>, <a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#ERASE\">ERASE<\/a><\/td>\n<td>Deletes one or more files.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#DIR\">DIR<\/a><\/td>\n<td>Displays a list of files and subdirectories in a directory.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#ECHO\">ECHO<\/a><\/td>\n<td>Displays messages, or turns command echoing on or off.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#ELSE\">ELSE<\/a><\/td>\n<td>Performs conditional processing in batch programs when &#8220;IF\" is not true.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#ENDLOCAL\">ENDLOCAL<\/a><\/td>\n<td>Ends localization of environment changes in a batch file.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#EXIT\">EXIT<\/a><\/td>\n<td>Quits the CMD.EXE program (command interpreter).<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#FOR\">FOR<\/a><\/td>\n<td>Runs a specified command for each file in a set of files.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#FTYPE\">FTYPE<\/a><\/td>\n<td>Sets the file type command.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#IF\">IF<\/a><\/td>\n<td>Performs conditional processing in batch programs.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#MD\">MD<\/a>, <a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#MKDIR\">MKDIR<\/a><\/td>\n<td>Creates a directory.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#MOVE\">MOVE<\/a><\/td>\n<td>Moves a file to a new location<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#PATH\">PATH<\/a><\/td>\n<td>Sets or modifies the PATH environment<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#PAUSE\">PAUSE<\/a><\/td>\n<td>Causes the command session to pause for user input.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#POPD\">POPD<\/a><\/td>\n<td>Changes to the drive and directory poped from the directory stack<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#PROMPT\">PROMPT<\/a><\/td>\n<td>Sets or modifies the string displayed when waiting for input.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#PUSHD\">PUSHD<\/a><\/td>\n<td>Pushes the current directory onto the stack, and changes to the new directory.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#RD\">RD<\/a> \/ <a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#RMDIR\">RMDIR<\/a><\/td>\n<td>Removes the directory.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#REM\">REM<\/a><\/td>\n<td>A comment command. Unlike double-colon (::), the command can be executed.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#REN\">REN<\/a> \/ <a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#RENAME\">RENAME<\/a><\/td>\n<td>Renames a file or directory<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#SET\">SET<\/a><\/td>\n<td>Sets or displays shell environment variables<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#SETLOCAL\">SETLOCAL<\/a><\/td>\n<td>Creates a child-environment for the batch file.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#SHIFT\">SHIFT<\/a><\/td>\n<td>Moves the batch parameters forward.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#START\">START<\/a><\/td>\n<td>Starts a program with various options.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#TIME\">TIME<\/a><\/td>\n<td>Displays or sets the system clock<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#TITLE\">TITLE<\/a><\/td>\n<td>Changes the window title<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#TYPE\">TYPE<\/a><\/td>\n<td>Prints the content of a file to the console.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#VER\">VER<\/a><\/td>\n<td>Shows the command processor, operating system versions.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#VERIFY\">VERIFY<\/a><\/td>\n<td>Verifies that file copy has been done correctly.<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#VOL\">VOL<\/a><\/td>\n<td>Shows the label of the current volume.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u6307\u4ee4\u7bc4\u4f8b\uff1a<\/h2>\n<h3><span id=\"FOR\" class=\"mw-headline\">FOR<\/span><\/h3>\n<p>Iterates over a series of values, executing a command.<\/p>\n<p>In the following examples,\u00a0%i is to be used from the command line while\u00a0%%i is to be used from a batch.<\/p>\n<p>Examples:<\/p>\n<ul>\n<li>for\u00a0%%i in (1,2,3) do echo\u00a0%%i\n<ul>\n<li>In a batch, echoes 1, 2, and 3. In a batch, the command must use a double percent sign.<\/li>\n<li>The remaining examples are intended to be directly pasted into a command line, so they use a single percent sign and include &#8220;@\" to prevent repetitive display.<\/li>\n<\/ul>\n<\/li>\n<li>for\u00a0%i in (1,2,3) do @echo\u00a0%i\n<ul>\n<li>From a command line, echoes 1, 2, and 3.<\/li>\n<li>The for command tries to interpret the items as file names and as patterns of file names containing wildcards.<\/li>\n<li>It does not complain if the items do not match existing file names, though.<\/li>\n<\/ul>\n<\/li>\n<li>for\u00a0%i in (1,2,a*d*c*e*t) do @echo\u00a0%i\n<ul>\n<li>Unless you happen to have a file matching the third pattern, echoes 1 and 2, discarding the third item.<\/li>\n<\/ul>\n<\/li>\n<li>for\u00a0%i in (1 2,3;4) do @echo\u00a0%i\n<ul>\n<li>Echoes 1, 2, 3, and 4. Yes, a mixture of item separators is used.<\/li>\n<\/ul>\n<\/li>\n<li>for\u00a0%i in (*.txt) do @echo\u00a0%i\n<ul>\n<li>Echoes file names of files located in the current folder and having the .txt extension.<\/li>\n<\/ul>\n<\/li>\n<li>for\u00a0%i in (&#8220;C:\\Windows\\system32\\*.exe\") do @echo\u00a0%i\n<ul>\n<li>Echoes file names matching the pattern.<\/li>\n<\/ul>\n<\/li>\n<li>for \/r\u00a0%i in (*.txt) do @echo\u00a0%i\n<ul>\n<li>Echoes file names with full paths, of files having the extension .txt located anywhere in the current folder including nested folders.<\/li>\n<\/ul>\n<\/li>\n<li>for \/d\u00a0%i in (*) do @echo\u00a0%i\n<ul>\n<li>Echoes the names of all folders in the current folder.<\/li>\n<\/ul>\n<\/li>\n<li>for \/r \/d\u00a0%i in (*) do @echo\u00a0%i\n<ul>\n<li>Echoes the names including full paths of all folders in the current folder, including nested folders.<\/li>\n<\/ul>\n<\/li>\n<li>for \/l\u00a0%i in (1,1,10) do @echo\u00a0%i\n<ul>\n<li>Echoes the numbers from 1 to 10.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=*\"\u00a0%i in (list.txt) do @echo\u00a0%i\n<ul>\n<li>For each line in a file, echoes the line.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=*\"\u00a0%i in (list1.txt list2.txt) do @echo\u00a0%i\n<ul>\n<li>For each line in the files, echoes the line.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=*\"\u00a0%i in (*.txt) do @echo\u00a0%i\n<ul>\n<li>Does nothing. Does not accept wildcards to match file names.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=1-3 delims=:\"\u00a0%a in (&#8220;First:Second::Third\") do @echo\u00a0%c-%b-%a\n<ul>\n<li>Parses a string into tokens delimited by &#8220;:\".<\/li>\n<li>The quotation marks indicate the string is not a file name.<\/li>\n<li>The second and third tokens are stored in\u00a0%b and\u00a0%c even though\u00a0%b and\u00a0%c are not expressly mentioned in the part of the command before &#8220;do\".<\/li>\n<li>The two consecutive colons are treated as one separator;\u00a0%c is not &#8220;\" but rather &#8220;Third\".<\/li>\n<li>Does some of the job of the cut command from other operating systems.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=1-3* delims=:\"\u00a0%a in (&#8220;First:Second::Third:Fourth:Fifth\") do @echo\u00a0%c-%b-%a:\u00a0%d\n<ul>\n<li>As above, just that the 4th and 5th items get captured in\u00a0%d as &#8220;Fourth:Fifth\", including the separator.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=1-3* delims=:,\"\u00a0%a in (&#8220;First,Second,:Third:Fourth:Fifth\") do @echo\u00a0%c-%b-%a:\u00a0%d\n<ul>\n<li>Multiple delimiters are possible.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=1-3&#8243;\u00a0%a in (&#8220;First Second Third,item\") do @echo\u00a0%c-%b-%a\n<ul>\n<li>The default delimiters are space and tab. Thus, they differ from the separators used to separate arguments passed to a batch.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=*\"\u00a0%i in (&#8216;cd&#8217;) do @echo\u00a0%i\n<ul>\n<li>For each line of the result of a command, echoes the line.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=*\"\u00a0%i in (&#8216;dir \/b \/a-d-h&#8217;) do @echo\u00a0%~nxai\n<ul>\n<li>For each non-hidden file in the current folder, displays the file attributes followed by the file name. In the string &#8220;%~nxai\", uses the syntax described at <a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#Percent_tilde\">#Percent tilde<\/a>.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;usebackq tokens=*\"\u00a0%i in (`dir \/b \/a-d-h`) do @echo\u00a0%~nxai\n<ul>\n<li>As above, but using the backquote character (`) around the command to be executed.<\/li>\n<\/ul>\n<\/li>\n<li>for \/f &#8220;tokens=*\"\u00a0%i in (&#8216;tasklist ^| sort ^&amp; echo End&#8217;) do @echo\u00a0%i\n<ul>\n<li>Pipes and ampersands in the command to be executed must be escaped using caret (^).<\/li>\n<\/ul>\n<\/li>\n<li>(for\u00a0%i in (1,2,3) do @echo\u00a0%i) &gt; anyoldtemp.txt\n<ul>\n<li>To redirect the entire result of a for loop, place the entire loop inside brackets before redirecting. Otherwise, the redirection will tie to the body of the loop, so each new iteration of the body of the loop will override the results of the previous iterations.<\/li>\n<\/ul>\n<\/li>\n<li>for\u00a0%i in (1,2,3) do @echo\u00a0%i &gt; anyoldtemp.txt\n<ul>\n<li>An example related to the one above. It shows the consequence of failing to put the loop inside brackets.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><span class=\"kw1\">--------------------------------------------\r\nfor<\/span> <span class=\"sy0\">%%<\/span><span class=\"re3\">i<\/span> <span class=\"kw1\">in<\/span> <span class=\"sy0\">(<\/span>a b c<span class=\"sy0\">)<\/span> <span class=\"kw1\">do<\/span> <span class=\"sy0\">(<\/span>\r\n    <span class=\"kw3\">echo<\/span> 1 <span class=\"sy0\">%%<\/span><span class=\"re3\">i<\/span>\r\n    <span class=\"kw1\">goto<\/span> :<span class=\"re0\">cont<\/span>\r\n    <span class=\"kw3\">echo<\/span> 2 <span class=\"sy0\">%%<\/span><span class=\"re3\">i<\/span>\r\n  :<span class=\"re0\">cont<\/span>\r\n    <span class=\"kw3\">echo<\/span> 3 <span class=\"sy0\">%%<\/span><span class=\"re3\">i<\/span>\r\n<span class=\"sy0\">)\r\n--------------------------------------------\r\n\r\n--------------------------------------------\r\n<\/span><span class=\"kw1\">for<\/span> <span class=\"sy0\">%%<\/span><span class=\"re3\">i<\/span> <span class=\"kw1\">in<\/span> <span class=\"sy0\">(<\/span>a b c<span class=\"sy0\">)<\/span> <span class=\"kw1\">do<\/span> <span class=\"kw1\">call<\/span> :<span class=\"re0\">for_body<\/span> <span class=\"sy0\">%%<\/span><span class=\"re3\">i<\/span>\r\n<span class=\"kw1\">exit<\/span> \/b\r\n \r\n:<span class=\"re0\">for_body<\/span>\r\n    <span class=\"kw3\">echo<\/span> 1 <span class=\"sy0\">%<\/span><span class=\"re3\">1<\/span>\r\n    <span class=\"kw1\">goto<\/span> :<span class=\"re0\">cont<\/span>\r\n    <span class=\"kw3\">echo<\/span> 2 <span class=\"sy0\">%<\/span><span class=\"re3\">1<\/span>\r\n  :<span class=\"re0\">cont<\/span>\r\n<span class=\"kw1\">exit<\/span> \/b\r\n<span class=\"sy0\">--------------------------------------------\r\n<\/span><\/pre>\n<h3><span id=\"String_processing\" class=\"mw-headline\">String processing<\/span><\/h3>\n<p>Getting a substring of a variable by position and length:<\/p>\n<p>Before running the following examples, ensure that\u00a0%a% equals &#8220;abcd\" by running this:<\/p>\n<ul>\n<li>set a=abcd<\/li>\n<\/ul>\n<p>The examples:<\/p>\n<ul>\n<li>echo\u00a0%a:~0,1%\n<ul>\n<li>Result: a<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~1,1%\n<ul>\n<li>Result: b<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~0,2%\n<ul>\n<li>Result: ab<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~1,2%\n<ul>\n<li>Result: bc<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~1%\n<ul>\n<li>Result: bcd<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~-1%\n<ul>\n<li>Result: d<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~-2%\n<ul>\n<li>Result: cd<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~0,-2%\n<ul>\n<li>Result: ab<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~0,-1%\n<ul>\n<li>Result: abc<\/li>\n<\/ul>\n<\/li>\n<li>echo\u00a0%a:~1,-1%\n<ul>\n<li>Result: bc<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Testing substring containment:<\/p>\n<ul>\n<li>if not &#8220;%a:bc=%\"==\"%a%\" echo yes\n<ul>\n<li>If variable a contains &#8220;bc\" as a substring, echo &#8220;yes\".<\/li>\n<li>This test is a trick that uses string replacement, discussed below.<\/li>\n<li>This test does not work if the variable contains a quotation mark.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Testing for &#8220;starts with\":<\/p>\n<ul>\n<li>if\u00a0%a:~0,1%==a echo yes\n<ul>\n<li>If variable a starts with &#8220;a\", echo &#8220;yes\".<\/li>\n<\/ul>\n<\/li>\n<li>if\u00a0%a:~0,2%==ab echo yes\n<ul>\n<li>If variable a starts with &#8220;ab\", echo &#8220;yes\".<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>String replacement:<\/p>\n<ul>\n<li>set a=abcd &amp; echo\u00a0%a:c=%\n<ul>\n<li>Result: abd<\/li>\n<\/ul>\n<\/li>\n<li>set a=abcd &amp; echo\u00a0%a:c=e%\n<ul>\n<li>Result: abed<\/li>\n<\/ul>\n<\/li>\n<li>set a=abcd &amp; echo\u00a0%a:*c=%\n<ul>\n<li>Result: d<\/li>\n<li>The asterisk only works at the beginning of the sought pattern; it does not work at the end or in the middle.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>See also the help for <a href=\"http:\/\/en.wikibooks.org\/wiki\/Windows_Batch_Scripting#SET\">SET<\/a> command: set \/?.<\/p>\n<p>Splitting a string by any of \" &#8220;, &#8220;,\", and &#8220;;\":<\/p>\n<dl>\n<dd>set myvar=a b,c;d<\/dd>\n<dd>for\u00a0%%a in (%myvar%) do echo\u00a0%%a<\/dd>\n<\/dl>\n<p>Splitting a string by semicolon, assuming the string contains no quotation marks:<\/p>\n<pre>@echo off\r\nset myvar=a b;c;d\r\nset strippedvar=%myvar%\r\n:repeat\r\nfor \/f \"delims=;\" %%a in (\"%strippedvar%\") do echo %%a\r\nset prestrippedvar=%strippedvar%\r\nset strippedvar=%strippedvar:*;=%\r\nif not \"%prestrippedvar:;=%\"==\"%prestrippedvar%\" goto :repeat<\/pre>\n<pre class=\"de1\"><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6559\u5b78\u7db2\u7ad9\uff1a BAT\uff1a\u6279\u8655\u7406\u6559\u5b78\uff08\u4e0a\uff09 @ \u96c5\u75de\u5c0f\u5b85:: \u96a8\u610f\u7aa9Xuite\u65e5\u8a8c BAT\uff1a\u6279\u8655\u7406\u6559\u5b78\uff08\u4e0b\uff09 @ \u96c5\u75de\u5c0f\u5b85:: \u96a8\u610f\u7aa9Xuite\u65e5\u8a8c Wikibooks Windows Batch Scripting \u7cfb\u7d71\u5167\u5efa\u6307\u4ee4\uff1a Command Description ASSOC Associates an extension with a file type (FTYPE). BREAK Sets or clears extended CTRL+C checking. CALL Calls one batch program from another. CD, CHDIR Displays or sets the current directory. CHCP Displays or sets the active code page [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/posts\/726"}],"collection":[{"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=726"}],"version-history":[{"count":0,"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/posts\/726\/revisions"}],"wp:attachment":[{"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/webnas.bhes.ntpc.edu.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}