Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello all,
I have "imax" environment variables
(%file_1%, %file_2%, %file_3%, etc.)
pointing to given physical files.In a loop, I want (let's say) to type them
one by one. Naively, I was thinking ofFOR /L %%i IN (1,1,%imax%) DO type XX
but XX is the problem... file_%%i does
not give me the physical file and
%file_%%i% has an incorrect syntax.Any suggestions ? May be by using an array ?
How one does that on MS DOS ?Thank you in advance.
Karim Aguenaou

Hi,
I honestly don't know what imax is, and I am hoping you will tell me.I did see the word dos though. So......
Note the (*.zip) is being searched for in the
bat below. You will need to change the *.zip part, but leave the ( ) there.This command will process one file at a time until it can no longer find any files with the zip extension. At which time it will then
quietly error out and end.If your files are txt just change it to (*.txt) dat (*.dat) ect.
*********************snip here***************
cls
@echo off
if %1!==}{! goto pass2
for %%a in (*.zip) do call %0 }{ %%a
goto end
:pass2
type %1 more:end
***********************snip here***************
Hope this of some help, and you will let me know what imax is.
Peace Goodwill and Happy Computing.
World Library

Hi,
Thanks for your reply. Sorry if I did not
expressed myself clearly. "imax" in my
example is the total number of files I want
to process. I chose the type command to
simplify.In one batch file (to be modified), the
environment variables are setSET %file_1%=d:\alpha.txt
SET %file_2%=d:\beta.dat
SET %file_3%=d:\gamma.dat
...
SET %file_20%=d:\omega.txtIn another batch file (not to be modified),
I want to type all the filesFOR /L %%i IN (1,1,20) DO type ??
And I don't know what to put in the ??..
With file_%%i, the program will try to type
the physical file file_1 but not
d:\alpha.txt.
%file_%%i% has an incorrect syntax.Thank you.
Karim

Sorry, but the FOR command does not work that way. It does not count numbers, it count files, this is how you can use it: (example)
for %A in (*.txt) do type %A
this finds all *.txt files and types them.
You can _not_ use FOR in the good old basic way, like 'FOR Y=0 TO 10' to do something several times. The FOR in DOS does not do the same thing.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |