Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, for just getting the filename of your batch the easiest way would be to just use <code>%~n0</code>.</p> <pre><code>@echo %~n0 </code></pre> <p>will output the name (without the extension) of the currently running batch file (unless executed in a subroutine called by <code>call</code>). The complete list of such “special” substitutions for path names can be found with <code>help for</code>, at the very end of the help:</p> <blockquote> <p>In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax:</p> <pre><code>%~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 </code></pre> <p>The modifiers can be combined to get compound results:</p> <pre><code>%~dpI - expands %I to a drive letter and path only %~nxI - expands %I to a file name and extension only %~fsI - expands %I to a full path name with short names only </code></pre> </blockquote> <p>To precisely answer your question, however: Substrings are done using the <code>:~start,length</code> notation: </p> <pre><code>%var:~10,5% </code></pre> <p>will extract 5 characters from position 10 in the environment variable <code>%var%</code>.</p> <p><strong>NOTE:</strong> The index of the strings is zero based, so the first character is at position 0, the second at 1, etc.</p> <p>To get substrings of argument variables such as <code>%0</code>, <code>%1</code>, etc. you have to assign them to a normal environment variable using <code>set</code> first:</p> <pre><code>:: Does not work: @echo %1:~10,5 :: Assign argument to local variable first: set var=%1 @echo %var:~10,5% </code></pre> <p>The syntax is even more powerful: </p> <ul> <li><code>%var:~-7%</code> extracts the last 7 characters from <code>%var%</code> </li> <li><code>%var:~0,-4%</code> would extract all characters except the last four which would also rid you of the file extension (assuming three characters after the period [<code>.</code>]).</li> </ul> <p>See <code>help set</code> for details on that syntax.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload