0

I've made a Program that Launches other programs, but here is the problem. You need to specify the path of the file in the code which means that the end-user needs to get into the code to specify the file which is not really the ideal situation.

I have solution in mind,when you launch the program a dialog box comes up and asks you to give it the file path so it can run the specified program. How would I go about doing something like this?

kero
  • 10,647
  • 5
  • 41
  • 51
Petzl11
  • 161
  • 1
  • 3
  • 18
  • Do you mind if the path is passed as a parameter instead of a dialogbox? e.g. `yourprogram.exe ` – Dale Nov 29 '13 at 08:29
  • No I don't mind if the path is passed as a parameter. – Petzl11 Nov 29 '13 at 08:34
  • [File / folder chooser dialog from a Windows batch script](http://stackoverflow.com/questions/15885132/file-folder-chooser-dialog-from-a-windows-batch-script) – captcha Nov 29 '13 at 09:17

2 Answers2

0

You can reads user input. e.g. edit the following snippet according to you need

ECHO User will have to enter the input file path.
set /p variable=Enter input files path please: 

The user can type as many letters as they want, and it will go into the delBuild variable.

Imran
  • 5,376
  • 2
  • 26
  • 45
0

You can also do the following

@echo off
set foo=%1
echo %foo%

%1 refers to the 1st parameter that you have passed it to the program. This first parameter will then be set to the variable %foo%. Here is the example:

C:\>test.bat "C:\passwd"
C:\passwd

Hope this helps :)

Update

You can make your program to execute another program by doing the following:

@echo off

REM `%~f1` will helps to expand `%1` to a fully qualitified path name
set "executable=%~f1"

REM checks if the first parameter exist. If it did not exist, a usage text will be displayed and the program will exit
if "%executable%"=="" (
    echo Usage: %0 path\to\executable
    goto :EOF
) else (
    call :program
    goto :EOF
)

:program
echo %executable% is starting...
start "" "%executable%"
goto :EOF
Dale
  • 1,903
  • 1
  • 16
  • 24
  • Thanks this and the other comment gave me an idea of how to do it, if I could I would tick both as correct :) – Petzl11 Nov 29 '13 at 08:42
  • I'm now confused again, could you possibly show this in an example? :) – Petzl11 Nov 29 '13 at 08:48
  • it is actually the same. All you have to do is to save the script and try running it in command prompt :) – Dale Nov 29 '13 at 08:51
  • Okay, now I understand that part, the other part i'm confused about is how i would put this into my code? So the user can declare the path that the program must go to , to open the file/script/program. – Petzl11 Nov 29 '13 at 08:56
  • Thank's this is perfect :D – Petzl11 Nov 29 '13 at 10:13