Solved Batch, assign text file's text to a variable then use it?

August 21, 2013 at 11:33:45
Specs: Windows 7
I am a beginner in batch.
I have a simple program which should go as the following:
the batch file should open, theres a text file called "source.txt" and another called 'target.txt'
it should assign the variables source and target to the text inside these text files
then it should use command 'xcopy' to copy the source to the target (using both variables)
PLEASE help
thanks :D

See More: Batch, assign text files text to a variable then use it?

Report •

#1
August 21, 2013 at 12:31:24
✔ Best Answer
set /p source=<source.txt
set /p target=<target.txt

here is a start for you. Xcopys pretty strait forward.

::mike


Report •

#2
August 21, 2013 at 12:44:37
Post a few lines of each.

=====================
M2 Golden-Triangle


Report •

#3
August 21, 2013 at 13:18:52
Well I believe i tried that
but when i do
xcopy source target
it takes 'source' as a word not a variable, so its like 'source' is not availible or something..

Report •

Related Solutions

#4
August 21, 2013 at 13:21:47
xcopy %source% %target%

adding this line by requirement

::mike


Report •

#5
August 21, 2013 at 13:28:34
Ah, sorry about that, Im not actually into batch i was just doing this code for my VB project, so i didn't know how to represent the variables.
anyways thank you very much, I actually tried it right now and it worked.

Report •

#6
August 21, 2013 at 13:37:10
no problem, didnt mean to assume, glad it worked

::mike


Report •

#7
September 8, 2013 at 09:49:18
To use the variable after it is SET you need to enclose the variable name with the % symbol.

Example:

xcopy %source% %target%

Hope this helps.


Report •

Ask Question