Batch file with variables in a txt file

Microsoft Windows server 2008 standard -...
August 6, 2010 at 03:42:12
Specs: Windows Server 2003
I need to create a batch file which will get its variables from a text file. What I'm trying to do is create a file which will use a 3rd party command for a backup of certain domains, and I'd like to have the domains list in a single .txt file.

For example:

backup to file
backup to file

in the txt file there sholud be a list of domains (,

Examples would be appreciated

Thank you!

See More: Batch file with variables in a txt file

Report •

August 6, 2010 at 06:39:29
To avoid any complexity I suggest the following structure for the script:

First set up your list file by typing one domain per line, e.g.


Then code the batch as belowe

@echo off

for /F "delims=" %%j in (List.txt) do call :EXEC %%j
goto :EOF


HERE YOUR SCRIPT referring the domain from List.txt as %*

goto :EOF
:: End_Of_Batch

This is the simplest way I can figure out for your job. About the %* it takes into account spaces in domain name, e.g.

copy "%*" D:\BKUPFile

Don't miss double quotes around the %* and don't declare :EOF as that is the standard return point in batch.

Report •

August 6, 2010 at 07:00:29
I made a script:

for /F %%l in (c:\test\domainlist.txt) do c:\progra~1\software\backupblah -%%l -tofile %%l.bak

and it seems to be working.

Is "delims=" and goto :EOF


important, or I can use it as it is?

Thank you for your time!

Report •

August 6, 2010 at 07:12:43
Your script works fine if there is no line in your list with embedded blanks (e.g. My Domain

My solution is more general but you can stay with the reported script if no spaces in names.

Report •

Related Solutions

Ask Question