tags:

views:

59

answers:

1

Hi, I have a batch file that is Run when a selfextraction file is executed. The self extracted files must be copied to to specefic place on the harddisc. In the batch file the user is asked where the path is (if it's not located the default place) Part of the batch file:

@ECHO OFF

IF EXIST "C:\Program Files\program\program.exe". (

    set PROGRAMPATH=C:\Program Files\

) ELSE (

    echo Program folder was not found. Please enter the path for Program

    set /p PROGRAMPATH=Path:
)

echo Copying data to "%PROGRAMPATH%"...


copy /Y "*.txt" "%PROGRAMPATH%"

Now for my question. If a user then enters a new path, is it possible to save that path. So when he executes the self extraction packagde again, it could remember that new path?

+1  A: 

You can save the path to some file under %USERPROFILE% by doing

  echo %PROGRAMPATH% > "%USERPROFILE%\AppData\Local\progpath.txt"

and then read it by doing

  set /p PROGRAMPATH=<"%USERPROFILE%\AppData\Local\progpath.txt"

The full batch will look like this

@ECHO OFF

set PROGRAMPATH=C:\Program Files\

IF EXIST "%USERPROFILE%\AppData\Local\progpath.txt". (
    set /p PROGRAMPATH=<%USERPROFILE%\AppData\Local\progpath.txt
)

IF NOT EXIST "%PROGRAMPATH%\program.exe". (
    echo Program folder was not found. Please enter the path for Program
    set /p PROGRAMPATH=Path:
)

echo %PROGRAMPATH%>"%USERPROFILE%\AppData\Local\progpath.txt"

echo Copying data to "%PROGRAMPATH%"...
copy /Y "*.txt" "%PROGRAMPATH%"
Ghostrider
Hi Ghostrider,Thanks, it looks like it could do the trick.But could you please show me were to put the lines?It doesnt work for me, so maybe I have inserted the lines in the wrong places.
Brian
hmmm, it writes the path nicely to progpath.txt but it never uses it. It always ask's me for the PROGRAMPATH
Brian
Make sure that you are using built in Windows echo (rather than echo.exe that comes with cygwin or similar). It worked for me on Windows 7. YMMV
Ghostrider
GREAT. It works fine nowThanks alot :o)
Brian
I've just notised one little issue.If I have space in the PATH, nothing is written to the progpath.txt.If I have no space in the PATH it works fine.Do you know how to fix that? :o)
Brian