Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a directory with several .o files which I want to be put into an enviroment variable, seperated by spaces. My code only puts the name of the last file (alphabetically) in the directory into the variable. What's wrong with this code?
---------------
set ofiles=
for %%o in (*.o) do set ofiles=%ofiles% %%o
echo %ofiles%
---------------Thanks.

It doesn't work, hard to explain why. Basically, the COMMAND.COM will read that line and replace the "%files%" varible for its current value, before executing the FOR cmd. So, you script is the same as:
for %%o in (*.o) do set ofiles= %%o
echo %ofiles%However, there are ways around that:
@echo off
if "%1"=="GoTo:" GOTO %2
set ofiles=
for %%? in (*.o) do call %? GoTo: setvar %%?
echo %ofiles%
goto eof
:setvar
set ofiles=%ofiles% %3
:eofThis another one will also work, if you'd prefer (it's simpler but less functional):
@echo off
echo SET OFILES=%%OFILES%% %%1> %TEMP%.\SETVAR.BAT
set ofiles=
for %%? in (*.o) do call %TEMP%.\SETVAR.BAT %%?
del %TEMP%.\SETVAR.BAT
echo %ofiles%-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br___________________________________________________________

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

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