Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows CMD script to get directory in which file exists

Tags:

windows

cmd

I have a executable file VSTO.exe & a try.bat file in one folder. I want to get the folder path of the bat file & concat that path with VSTO.exe.

I have this script in my try.bat.

"%~fp0\VSTO.exe" /q

but it creates path: "G:\test\try.bat\VSTO.exe" . I want to get a path "G:\test\VSTO.exe"

can anyone tell me how do i do that?

like image 954
Sangram Nandkhile Avatar asked Feb 21 '23 15:02

Sangram Nandkhile


2 Answers

"%~dp0\VSTO.exe" /q

is the exact answer.

How to get folder path from file path with CMD

like image 106
Sangram Nandkhile Avatar answered Feb 23 '23 04:02

Sangram Nandkhile


Try with this

SET CURDIR=%CD%
"%CURDIR%\VSTO.EXE" /q

The %CD% pseudo-variable expands to the current working directory.
Type SET /? to see other pseudo-variable (last page)

like image 22
Steve Avatar answered Feb 23 '23 03:02

Steve