Batch file Get User Input Write to Txt file

Netgear / Dg834g
March 14, 2011 at 07:54:14
Specs: Windows XP SP3, 4000+ / 2gb DDR
I have a fairly complicated batch file which works fine, except
I run it from a CD, (READ ONLY) one path is dynamic and
points to a directory on the computer. (This could be any
directory needing repeat checking such as a cache
directory / Drive or Folder name)

So has to be SET depending on which computer it is used
on, and the batch is run on a schedule for a time to run a
scanner to test a directory for malware OR virus.

So on repeat runs, I need it to GET the previously stored PATH
from C:\batch\my-path.txt

However on the FIRST RUN this file does not exist and need a simple
prompt for the path, so I want my Batch file to ask for USER INPUT
i.e. (get path) then store this PATH in C:\batch\my-path.txt

Future repeat runs of the BATCH file then gets this path
from C:\batch\my-path.txt and stores it in a variable such as

I have no problem using a choice menu to delete or reset this
file in the event a new path needs to be set, I just don't know
how to get user input and store it in C:\batch\my-path.txt
and how to input it as a variable for the path to scan?

I have checked many other posts on here but could not find
anything suitable for my needs.

Any idea's please ?


See More: Batch file Get User Input Write to Txt file

Report •

March 14, 2011 at 14:25:11
Prompt for input and store the result

set /P  mypath=Enter Path Name^>
echo.%mypath%> C:\patch\my-path.txt

Obviously you should check what user enters to avoid unexpected behaviors.

To set a variable from the content of the file

set /P mypath=< C:\patch\my-path.txt

Report •

March 14, 2011 at 15:24:31
Oh Thank you so much IVO
Will try, but hope fully it will only be a competent person :)

Michelle xxx

Report •

March 14, 2011 at 20:30:00
Dear IVO,
Just ran some tests it works perfectly THANK YOU <3

I also set some default's to point to floppy A: as default value's as a safety measure to avoid NULLS, BUT ALSO PUT SOME IF EXIST statements for the text files as well just in case, and then I added another variant path using your code to point to the CD drive, by doing this I could use some error checking to check if a known file on the CD exists, so if the user input fails on the first path that points to the CD then the batch exits with a stern warning :)

My batch is much to big to put here but will include a simplified sample later of what I have done for others to see after I have got some sleep, 26 hours is a long time to be going for me ;)

Again thanks xxx

Report •

Related Solutions

Ask Question