1

I need to create a Windows Batch File that can remember what user type for a short time.

I mean when I click my .BAT File, It should ask like Please enter your program installation directory.

if user types nothing the batch file should exit otherwise it should set the text (The installation directory in my case)that user typed before to a variable like %DIRECTORY%.

From there, the %DIRECTORY% should behave like a variable and should has the ability to be mentioned like cd %DIRECTORY , COPY %DIRECTORY/MyApp.exe in next commands I use.

How can I do this?

I also tried to do this:

@echo off
color 1E
title TESTING BATCH FILE
echo Enter your APP INSTALLATION DIRECTORY.  
echo.
echo.
set /p DIR=ENTER THE INSTALLATION DIRECTORY: <<<Prompting From The User>>>
echo DIRECTORY="%DIR%" <<<Set what user typed as a variable>>>
cd %DIR% <<<Execute further commands using it>>>
pause
exit

Thanks in Advance.

GTAVLover
  • 1,407
  • 3
  • 22
  • 41
  • 1
    why have %DIRECTORY%? You've already got the exact same information in %DIR%, which is where `set /p` put the user input. and you can't set system-wide env vars from a cmd shell. that can only be done from the system control panel. – Marc B Jul 12 '16 at 14:26
  • 1
    if you want to set a variable, then `set` it, don't `echo` it. – ths Jul 12 '16 at 14:28
  • 1
    `set DIRECTORY="%DIR%"` <<>> – Aacini Jul 12 '16 at 14:28
  • 1
    Also, rather than asking the user to type the directory location, you could have the user [browse for the directory to use](http://stackoverflow.com/questions/15885132/file-folder-chooser-dialog-from-a-windows-batch-script). – rojo Jul 12 '16 at 14:31
  • @rojo It worked well.......... – GTAVLover Jul 12 '16 at 15:09
  • @MarcB YES after getting information from `%DIR%` , I need it to be mentioned in some commands......how to do this? – GTAVLover Jul 12 '16 at 15:10
  • @Aacini Yes the line you're showing is how I tried to make it a variable using `%%` – GTAVLover Jul 12 '16 at 15:58
  • To store something in a user- or system-related environment variable permanently use `setx` (type `setx /?` for help)... – aschipfl Jul 12 '16 at 21:40
  • `setx` .......I never heard or tried this before........I will try to use this in commmands – GTAVLover Jul 13 '16 at 00:07

0 Answers0