Jump to content

Guest, which answer was the most helpful?

If any of these replies answered your question, please take a moment to click the 'Mark as solution' button on the post with the best answer.
Marking posts as the solution will help other community members find answers to their questions quickly. Thank you for your help!

Featured Replies

Posted

If I run the following script in a directory with two files named test1.txt &

test2.txt, FILELIST should have the value of "Test2.txt;Test1.txt;NOFILES".

Instead it has the value of "Test2.Txt;NOFILES". Can any one tell me why? Or

how to get it to work correctly?

 

@SET FILELIST=NOFILES

@for %%f in (*.txt) do @(

@echo %%f

@set FILELIST= %%f;%FILELIST%

@echo %FILELIST%

)

 

Thanks,

"Buddy Lott" <BuddyLott@discussions.microsoft.com> wrote in message

news:94460634-69B5-4DAF-B70A-D0D89DA358CF@microsoft.com...

> If I run the following script in a directory with two files named

> test1.txt &

> test2.txt, FILELIST should have the value of

> "Test2.txt;Test1.txt;NOFILES".

> Instead it has the value of "Test2.Txt;NOFILES". Can any one tell me why?

> Or

> how to get it to work correctly?

>

> @SET FILELIST=NOFILES

> @for %%f in (*.txt) do @(

> @echo %%f

> @set FILELIST= %%f;%FILELIST%

> @echo %FILELIST%

> )

>

> Thanks,

>

 

Try this instead:

 

@echo off

SetLocal EnableDelayedExpansion

SET FILELIST=NOFILES

for %%f in (*.txt) do (

echo %%f

set FILELIST= %%f;!FILELIST!

echo !FILELIST!

)

 

Run set /? from a Command Prompt to find out more

about delayed expansion.

"Buddy Lott" <BuddyLott@discussions.microsoft.com> wrote in message

news:94460634-69B5-4DAF-B70A-D0D89DA358CF@microsoft.com...

> If I run the following script in a directory with two files named

> test1.txt &

> test2.txt, FILELIST should have the value of

> "Test2.txt;Test1.txt;NOFILES".

> Instead it has the value of "Test2.Txt;NOFILES". Can any one tell me why?

> Or

> how to get it to work correctly?

>

> @SET FILELIST=NOFILES

> @for %%f in (*.txt) do @(

> @echo %%f

> @set FILELIST= %%f;%FILELIST%

> @echo %FILELIST%

> )

>

> Thanks,

>

 

Sorry, I meant

 

for /?

 

at the Command Prompt.

Re: Why is an enviroment variable not updated correctly in a for l

 

The case I posted works using the SetLocal EnableDelayedExpansion.... but it

doesn't seem to work for this case. Why?

 

SetLocal EnableDelayedExpansion

@FOR /R %%f IN (*.cpp *.c) DO (

 

if exist "%%~nf.lnt". SET FILE_SPECIFIC_CONFIG="%%~pf%%~nf.lnt".

if exist "%~p1\pclint.lnt". SET DIR_SPECIFIC="%~p1\pclint.lnt".

lint-nt "-os(%%~pf%%~nf.lint)" %LINT_INCLUDE% !DIR_SPECIFIC!

!FILE_SPECIFIC_CONFIG! u:\Projects\BAC\B_BC\sw\BC.lnt -u %%f

)

 

"Pegasus (MVP)" wrote:

>

> "Buddy Lott" <BuddyLott@discussions.microsoft.com> wrote in message

> news:94460634-69B5-4DAF-B70A-D0D89DA358CF@microsoft.com...

> > If I run the following script in a directory with two files named

> > test1.txt &

> > test2.txt, FILELIST should have the value of

> > "Test2.txt;Test1.txt;NOFILES".

> > Instead it has the value of "Test2.Txt;NOFILES". Can any one tell me why?

> > Or

> > how to get it to work correctly?

> >

> > @SET FILELIST=NOFILES

> > @for %%f in (*.txt) do @(

> > @echo %%f

> > @set FILELIST= %%f;%FILELIST%

> > @echo %FILELIST%

> > )

> >

> > Thanks,

> >

>

> Sorry, I meant

>

> for /?

>

> at the Command Prompt.

>

>

>

Re: Why is an enviroment variable not updated correctly in a for l

 

I don't think that the syntax FOR /R %%f IN (*.cpp *.c) DO

is a valid use of wild cards. Since your batch files are quite

advanced, I recommend that you post your questions here:

 

alt.msdos.batch.nt

 

They love to dig their teeth into this sort of thing!

 

 

"Buddy Lott" <BuddyLott@discussions.microsoft.com> wrote in message

news:9EC548CF-C42A-4E89-BAFF-BA534BE56F99@microsoft.com...

> The case I posted works using the SetLocal EnableDelayedExpansion.... but

> it

> doesn't seem to work for this case. Why?

>

> SetLocal EnableDelayedExpansion

> @FOR /R %%f IN (*.cpp *.c) DO (

>

> if exist "%%~nf.lnt". SET FILE_SPECIFIC_CONFIG="%%~pf%%~nf.lnt".

> if exist "%~p1\pclint.lnt". SET

> DIR_SPECIFIC="%~p1\pclint.lnt".

> lint-nt "-os(%%~pf%%~nf.lint)" %LINT_INCLUDE% !DIR_SPECIFIC!

> !FILE_SPECIFIC_CONFIG! u:\Projects\BAC\B_BC\sw\BC.lnt -u %%f

> )

>

> "Pegasus (MVP)" wrote:

>

>>

>> "Buddy Lott" <BuddyLott@discussions.microsoft.com> wrote in message

>> news:94460634-69B5-4DAF-B70A-D0D89DA358CF@microsoft.com...

>> > If I run the following script in a directory with two files named

>> > test1.txt &

>> > test2.txt, FILELIST should have the value of

>> > "Test2.txt;Test1.txt;NOFILES".

>> > Instead it has the value of "Test2.Txt;NOFILES". Can any one tell me

>> > why?

>> > Or

>> > how to get it to work correctly?

>> >

>> > @SET FILELIST=NOFILES

>> > @for %%f in (*.txt) do @(

>> > @echo %%f

>> > @set FILELIST= %%f;%FILELIST%

>> > @echo %FILELIST%

>> > )

>> >

>> > Thanks,

>> >

>>

>> Sorry, I meant

>>

>> for /?

>>

>> at the Command Prompt.

>>

>>

>>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...