07-17-2017 12:54 AM
Hi,
I am trying to run a .bat file (i.e. “mybatfile.bat”) from the tools menu. At the moment I manage to do that by customizing the Tools Menu: Tools-->Customize-->Add then in the “Menu item name” box I use “RunBatFile” and in the “Program Name” box I use the “Browse” facility to navigate and select the “mybatfile.bat” file. Everything work fine however, the content of the file “mybatfile.bat” differs from project to project and, instead of creating new menu items for each project I would like to create a .bat file for each project and get the relative path to it in the “Program Name” box.
Is there any way of doing that?
Thank you!
07-17-2017 02:23 AM - edited 07-17-2017 02:26 AM
I created this schema that should address your problem.
Let's suppose your target batch file is the simplest of all:
@echo off echo The target folder is %1 pause
this prints in a command prompt the name of the first parameter received and waits for the user to press a key.
This batch file is located somewhere on your system, e.g. c:\myfolder\mybatchfile.bat.
Now in your project folder you must create another batch file that calls the first one passing the appropriate parameter:
call c:\myfolder\mybatchfile.bat %~dp1
This file calls the preceding one passing the drive and pathname only extracted from the first parameter: of course you must pass a valid pathname to it.
Finally, create a tools menu option this way:
%FILE% will have the name of the filename open in the active window of the workspace (or the workspace itself if no file is in editing).
If you do not have the calling batch file in the project folder you will receive an "Unable to execute command line" error message.
To understand that strange "%~dp1" clause, open a command prompt and enter "CALL /?" to see the help on the command.