Windows – How to i execute a .bat file using the relative path to it, on Windows 7

windows 7

I mean, if i'm in the folder foo, and within it there's another folder called bar, and whithin bar folder, there's a file.bat.
In this scenario, i can't just type foo/bar/file.bat. I have to type the entire path to get the file executed, i.e (c:/foo/bar/file.bat).

Is there a way i can do just foo/bar/file.bat and execute the file.bat, without having to type the entire path to the file.bat?

P.S: I'm talking about Windows Command Prompt.

Sorry for my bad english.

Best Answer

Your example code has forwards slashes instead of backward slashes (if you didn't notice).

Yes, if you are in foo with command prompt you can run bar\file.bat to open that batch script. You would not run as you say " foo\bar\file.bat " because you are already in foo, as you have said. But if you are in a different node (i.e C:\foo\john) and want to access bar\file.bat you must run ..\bar\file.bat

If you want to navigate to any folder you may run cd [nextfoldernodename]. For example if you are in C: you may run cd foo to get in the foo folder, or if you type cd foo\bar you can get in the bar folder. (cd stands for change directory).

Related Question