How can I make SET to set a variable based on txt content?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
keropi
Posts: 5
Joined: 27 Feb 2010 18:36
Location: Greece

How can I make SET to set a variable based on txt content?

#1 Post by keropi » 28 Feb 2010 13:13

Hiya!

is there a way to make SET create a variable from a small txt ?
let's say I have 1.txt that has inside: 123
and I want to make a variable, let's say: TEST1
so is there a way to make a batch file to SET TEST1=1.txt_content
so I get TEST1=123
??

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How can I make SET to set a variable based on txt content?

#2 Post by aGerman » 28 Feb 2010 14:57

Code: Select all

set /p "TEST1="<"1.txt"


Regards
aGerman

keropi
Posts: 5
Joined: 27 Feb 2010 18:36
Location: Greece

Re: How can I make SET to set a variable based on txt content?

#3 Post by keropi » 28 Feb 2010 17:06

I did it and the result was this variable:
/P "test1="
I guess plain dos from win98se does not get this command... :cry:

keropi
Posts: 5
Joined: 27 Feb 2010 18:36
Location: Greece

Re: How can I make SET to set a variable based on txt content?

#4 Post by keropi » 01 Mar 2010 03:51

OK I have found this solution that works in plain old DOS:

Code: Select all

@echo off
echo @echo off> director.bat
echo set getdir_=%%2>> director.bat
echo echo %%getdir_%%>> director.bat
dir | find "Directory"> go.bat
call go
if exist director.bat del director.bat
if exist go.bat del go.bat


getdir_ is the variable, edit it to whatever name you want :mrgreen:

Post Reply