I know that %0
contains the full path of the batch script, e.g. c:\path\to\my\file\abc.bat
I would path
to be equal to c:\path\to\my\file
How could I achieve that ?
Try CD C:\Temp <CR> ECHO %CD% ( <CR> is newline...) Also, if you right-click on the script and select "Run as Administrator", the starting current directory is C:\Windows\System32 regardless of where the script is located.
Go to the destination folder and click on the path (highlights in blue). type cmd. Command prompt opens with the path set to your current folder.
The PATH is an environment variable containing a list of directories, separated by semi-colons (;). It is used by the command processor to find the programs or executables it needs. The PATH variable can be set in two ways: SET PATH=c:\bat;c:\dos. or: PATH c:\bat;c:\dos.
Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME. bat.
%~dp0
will be the directory. Here's some documentation on all of the path modifiers. Fun stuff :-)
To remove the final backslash, you can use the :n,m
substring syntax, like so:
SET mypath=%~dp0 echo %mypath:~0,-1%
I don't believe there's a way to combine the %0
syntax with the :~n,m
syntax, unfortunately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With