2

I have a batch script line like below :

for %%v in (aa bb* cc) do echo mget %%v

I am getting output as :

mget aa

mget cc

But I need output as :

mget aa 

mget bb*

mget cc

Update

I have a batch file called ftp.bat and a parameter file called parm.txt. parm.txt looks like:

server=xxx.yyy.com
user=abc
pwd=xyz
files=aa bb* cc dd ------(this varies)

I need to extract these values in my batch file to construct ftp commands. Using delim concept I've got server, user, pwd but I need to separate the files.

1 Answer 1

4

If you use for with a wildcard, the interpreter looks for all files matching the wildcard ("bb*" in this case) and passes the names of the files to your command. It won't pass a string containing a '*' (or a '?') to your command.

Instead, create a text file called filelist.txt containing:

aa
bb*
cc

and use the command:

for /F %%I in (filelist.txt) do echo mget %%I

Update

Apparently, there is already a filelist.txt with multiple items on each line. Create a batch file called vary.bat:

@echo off
:more
if "%1"=="" (goto finished)
echo mget %1
shift
goto more
:finished

This takes a variable number of parameters and echoes an mget for each one. Call it with something like:

for /F "tokens=*" %%I in (filelist.txt) do vary %%I

Another update

This will read parm.txt, create a variable for each of server, user, pwd and files, then call vary.bat (described above) on the list of files.

for /F "delims== tokens=1,2" %%I in (parm.txt) do set %%I=%%J
vary %files%
Sign up to request clarification or add additional context in comments.

11 Comments

Thanks. But I still have the problem. Yes, I have a seperate file as you said. But that file has variable(values) assigned with list of values like values=aa bb* cc . In this case it is echo'ing only first value which is aa.
Do you have a fixed number of values in each list, or does it vary?
And the number of values varies, it is dynamic.
Actually a separate file is not needed. You could have a subroutine call instead.
@user1171858: Make sure to add goto :eof just before the :vary line, to jump over the subroutine when the main script is done working, to avoid the unnecessary extra "call" of the subroutine.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.