Input Data from a text file into a batch file variable.

Posted on 2005-04-04
Medium Priority
Last Modified: 2010-04-13
Hello all,

I have a small problem, I have a batch file that I wrote (see code below) that I need to input data from a text file into a variable within the batch file.  The data the the text file will contain is simply today's date in the following format (Mon 04/03/2005) which will be read into the batch file and be used the following day.  In short what I'm trying to accomplish is a date misus one calculation without writing some big log script to do the calculations.  I wrote a VB app that does exactly what I need it to do, but the securtiy nazi's around here told me that I can't use exe's or VB scripts on the servers...

Code Sample:

@echo off

rem setting the current date

Rem TempDate <--  This is the variable that I want to get from another file.

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

set name=ex%yy%%mm%%dd%.log

rem creating file name using current date and
rem copying to another location using the same name.
rem change copy command to reflect desired locations.

copy c:\temp\ex%yy%%mm%%dd%.log c:\temp2\ex%yy%%mm%%dd%.log

Question by:PJan8724
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 85

Accepted Solution

oBdA earned 1000 total points
ID: 13704707
Assuming this date is the only line in the text file, simply use something like this (NT4 or later):

@echo off
set DateFile=C:\temp\test.txt
for /f "delims=" %%a in ('type "%DateFile%"') do set TempDate=%%a

Author Comment

ID: 13707340
Hey oBda,

Thanks for the help, I actually came up with a similar solution yesterday after doing some more research but yours is a little better then mine so I'm going to go with.  However I did want to say thanks for all you help.

Pete J.

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question