DOS Script

bobcaputo
bobcaputo used Ask the Experts™
on
I have a file which contains the YYYYMM of curret day. I would like to read this and input it into a variable in my DOS script.

How do I get this???
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
If the file contains only that data and nothing else, here is a sample that reads it from mydate.txt into a variable called myvar and outputs it to the screen:

for /f "tokens=* delims= " %%x in (mydate.txt) do set myvar=%%x
echo %myvar%
Easier way...

set /p var=<mydate.txt

Of course you don't need to read the file (per se) if you simply want today's date info.  If your date variable is Mon 08/08/2011 then you only need to split that string...

set yyyy=%date:~10,4%
set yy=%date:~12,2%
set mm=%date:~4,2%
set dd=%date:~7,2%

Author

Commented:
Excellant, thanks everyone.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial