Computing.Net > Forums > Disk Operating System > trouble with environment variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

trouble with environment variables

Reply to Message Icon

Name: Karim
Date: March 3, 1999 at 07:02:17 Pacific
Comment:

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 of

FOR /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



Sponsored Link
Ads by Google

Response Number 1
Name: World Library
Date: March 4, 1999 at 18:27:41 Pacific
Reply:


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


0

Response Number 2
Name: Karim
Date: March 5, 1999 at 02:35:49 Pacific
Reply:

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 set

SET %file_1%=d:\alpha.txt
SET %file_2%=d:\beta.dat
SET %file_3%=d:\gamma.dat
...
SET %file_20%=d:\omega.txt

In another batch file (not to be modified),
I want to type all the files

FOR /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


0

Response Number 3
Name: Jakob Berglund
Date: May 30, 1999 at 23:30:42 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: trouble with environment variables

Problem with environment variable. www.computing.net/answers/dos/problem-with-environment-variable/15441.html

parse environment variable www.computing.net/answers/dos/parse-environment-variable/12203.html

set versus @set? plus can environment variables be displayed www.computing.net/answers/dos/set-versus-set-plus-can-environment-variables-be-displayed/3510.html