variable in batch file

Microsoft Windows xp professional w/serv...
May 27, 2010 at 23:31:01
Specs: Windows XP
I have a dos batch file which appends data to the end of a record (see below). The data is repeated numerous times. Is it possible to create a variable instead and then reference that variable. This would eliminate the number of times it needs to be changed.

I tried the SET command (i.e. SET date1=05272010), but then when I replace all my 05272010 in the code with date1, it displays the value date1 instead of 05272010. Additionally, I tried using the %date1% in places where 05272010 appeared but still no luck.

Any help is greatly appreciated.

p.s. Our office is planning on converting to Windows 7 in the near future. Would you happen to know if batch files will still work in Windows 7?
::This batch file does the following:
:: 1) appends a date to the end of a file. Done multiple times.
:: 2) appends all files together
:: 3) deletes files

del test_combined_data.txt

@echo off & setlocal EnableDelayedExpansion

for /F "tokens=* delims=" %%j in (c:\users\mom\test05272010.txt) do (echo %%j 05272010 >> testnew_05272010.txt)
for /F "tokens=* delims=" %%j in (c:\users\mom\test05282010.txt) do (echo %%j 05282010 >> testnew_05282010.txt)
for /F "tokens=* delims=" %%j in (c:\users\mom\test05292010.txt) do (echo %%j 05292010 >> testnew_05292010.txt)

copy testnew_05272010.txt + testnew_05282010.txt + testnew_05292010.txt test_combined_data.txt

del testnew_05272010.txt
del testnew_05282010.txt
del testnew_05292010.txt

:: End_Of_Batch


See More: variable in batch file

Report •

May 28, 2010 at 00:13:17
edited (to finish the job! sorry i forgot the other two steps.)
this one combines steps one and two into one
since there's really no need to create 3 files
only to delete them right away.

@echo off & setlocal enabledelayedexpansion
set mo=05
set yr=2010
for %%z in (28 29 30) do (
for /F "tokens=* delims=" %%j in (c:\users\mom\test%mo%%%z%yr%.txt) do echo %%j %mo%%%z%yr% >> alltests.txt

Report •

May 28, 2010 at 05:13:35
Thank you this worked great. But I do have two more questions:

1) how can I incorporate the variable within my step when I need to combine all the newly created files ?

2) how can I incorporate the variable in my the delete step when I delete the files

Report •

Related Solutions

Ask Question