Windows Scripting: Difference between revisions

From Andreida
(Created page with "change to the directory of the executed script: chdir /D %~dp0 The /D allows to change drives too.")
 
No edit summary
Line 1: Line 1:
=== directory of current script ===
change to the directory of the executed script:
change to the directory of the executed script:
chdir /D %~dp0
chdir /D %~dp0
The /D allows to change drives too.
The /D allows to change drives too.

=== functions ===
<pre>
@echo off
echo 1
call :func_1 2
call :func_1 3
echo 4
exit /B

:func_1
echo %1 (called in a function)
exit /B 0
</pre>

Output:
<pre>
>test
1
2 (called in a function)
3 (called in a function)
4
</pre>

Revision as of 16:42, 19 September 2020

directory of current script

change to the directory of the executed script:

chdir /D %~dp0

The /D allows to change drives too.

functions

@echo off
echo 1
call :func_1 2
call :func_1 3
echo 4
exit /B

:func_1
echo %1 (called in a function)
exit /B 0

Output:

>test
1
2 (called in a function)
3 (called in a function)
4