Set a variable to file contents
Moderator: DosItHelp
-
- Posts: 2
- Joined: 04 Feb 2013 05:50
Set a variable to file contents
Hi,
How to I grab the (simple) contents of a file (which will be YYYYMMDD each day) and assign it to a variable?
So, the file mydatefile.txt contains 20130204 and I want the batch script to assign '20130204' to the variable a.
(All of the ancillary things I've worked thru, and can do - except for assigning - the contents of a file - to a variable.)
For you unixy-types:
a=`cat mydatefile.txt`
(This will be for a batch script that contains a once-per-day routine and executed from Startup)
tia,
Matt
Re: Set a variable to file contents
Code: Select all
@echo off
set /p "a="<mydatefile.txt
echo "%a%"
pause
Re: Set a variable to file contents
Hi,
Following will work.
Following will work.
Code: Select all
@echo off
for /f "usebackq tokens=* delims=" %%a in ("mydatefile.txt") do call :Fun "%%a"
exit /b
:Fun
set str1=%~1
echo %str1%
exit /b
-
- Posts: 2
- Joined: 04 Feb 2013 05:50
Re: Set a variable to file contents
foxidrive wrote:Code: Select all
@echo off
set /p "a="<mydatefile.txt
echo "%a%"
pause
Worked great.
Just what I was looking for!
Thanks,
Matt