Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Windows batch variable starts with a specific string

People also ask

What does && do in batch file?

&& runs the second command on the line when the first command comes back successfully (i.e. errorlevel == 0 ). The opposite of && is || , which runs the second command when the first command is unsuccessful (i.e. errorlevel != 0 ).

What does 0 |% 0 Do in batch?

What it is: %0|%0 is a fork bomb. It will spawn another process using a pipe | which runs a copy of the same program asynchronously. This hogs the CPU and memory, slowing down the system to a near-halt (or even crash the system).


Use the variable substring syntax:

IF "%variable:~0,3%"=="ABC" [...]

If you need the path to the batch file without the batch file name, you can use the variable:

%~dp0

Syntax for this is explained in the help for the for command, although this variable syntax extends beyond just the for command syntax.


to find batch file location use %0 (gives full patch to current batch file) or %CD% variable which gives local directory