Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to write a simple batch program to ask a user to input a file name, then to use that file name in a copy statement..
example:
Input file name: filename
copy c:\temp\filename g:\temp\filenamehow do I do this???

This shows how to get user input and send to %input% variable:
For Win9x/DOS6.22:
@echo off
echo Type in input
echo.>%temp%.\$$tmp.bat
FC con nul /lb1 /n |FIND "1:" >> %temp%.\$$tmp.bat
echo e100'set input='>%temp%.\$$tmp.dat
echo w>>%temp%.\$$tmp.dat
echo q>>%temp%.\$$tmp.dat
debug %temp%.\$$tmp.bat < %temp%.\$$tmp.dat > nul
call %temp%.\$$tmp.bat
for %%d in (tmp.bat tmp.dat) do if exist %temp%.\$$%%d del %temp%.\$$%%d
echo INPUT="%INPUT%"!!! Watch out for line wrapping !!!
For NT systems:
set /p input=Type input:
The Win9x method does NOT include checking for errors on input. For further information, view my FAQ.
After getting user's input to a variable, simply do:
copy c:\temp\%input% g:\temp\%input%
HTH
-- Secret_Doom - Leonardo Pignataro --
secret_doom@hotmail.com
www.batch.hpg.com.br

this works except for a space in my file name. here is an example:
input=filename.ext
copy g:\temp\ filename.ext c:\temp\...
^
where does this space come form????

The problem is this f***ing forum!
Note the following line:echo e100'set input='>%temp%.\$$tmp.dat
There are _TWO_ spaces between "set" and "input" !
That will do it.
-- Secret_Doom - Leonardo Pignataro --
secret_doom@hotmail.com
www.batch.hpg.com.br

I've tried all of the above options for taking a user input and using it in a filename or copy command but keep getting out of environment errors, anyone any ideas?

I read sumwhere in a PC mag that u can use %i as input (eg in my ping bomber that i tried: PING %i l 65500 n 10000 didnt work)... i think u could use that sumhow :S try it... If not, add me 2 messenger and use VB ;)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |