1.

Solve : can anyone help me with the lists??

Answer»

Hi,
i want to write a program in which a list is to be appended with a new element.
i used the following lines of code
set list=
for %%i in (*) do set list=!list! %i
echo %list%

it's not working
can anyone please help me out??
i'm using windows ntI'm having trouble figuring out what result you're looking for but this may work:

Code: [Select]set list=
for %%i in (*) do set list=!list! %%i
echo %list%

Not sure if setlocal is valid on NT, but this may work also:

Code: [Select]setlocal ENABLEDELAYEDEXPANSION
set list=
for %%i in (*) do set list=!list! %%i
echo %list%

Hope this helps. 8-)no...it dint work..any more ideas please
small modification, my OS is windows 2000.. not NT
The output that i'm getting is

!list! <last_file_name>Quote

i want to write a program in which a list is to be appended with a new element

The SECOND example provided should have produced the desired output. Please EXPLAIN in more detail what result you're looking for.

8-)Thank u for the response..
I want all the files in the folder to be in that list. do that i can PROCESS the list using a for LOOP later.
I have tried the second example also..but still i'm getting the same result.
If not this is there any other method to get all the files in the directory in a list.


Quote

The second example provided should have produced the desired output. Please explain in more detail what result you're looking for.

8-)
A for loop can run a command allowing you to process each file individually. A simple example would be:

Code: [Select]for /f "tokens=* delims=" %%i in ('dir /b') do echo %%i

Your method of creating a single string with all the file names will create problems should any of the file names have emedded spaces.

Need more info to give you a definitive answer, for example do you need the full paths of the files, or what about sub-directories and what do you need to do with this list? 8-)The actual THING that i want to do with the code is that
i have a folder which has some sub-folders.
each sub-folder has some files.
i want to write filenames(with path) of all the files in sub-folders in a file.

So,i wanted to add all the sub-folders to a list. then
i want to process each of the element in the list(each subfolder name)
to get the files in them and write the names in an output file.
for this i wanted to get a listYou just want a list with all the (sub)folders and files with path in a textfile which you can read out later?

dir /s /b >list.txt

hope it helps
uli

@Sidewinder: NT icludes "setlocal".Thank u...It's almost working...

Ok...can u tell me how to add the subdirectories to the list? Isn't there a method to make a list other than using
set list = !list! %%i
i'm not able to get the expected result even after using
setlocal enabledelayedexpansion
Quote
i want to write filenames(with path) of all the files in sub-folders in a file.

This could be done with multiple for instructions, but the dir command has recursion built in:

dir /a:-d /s /b >list.txt

setlocal enabledelayedexpansion "is useful for getting around the limitations of the current expansion which happens when a line of text is read, not when it is executed". Microsoft Command Line Help

8-)

thank u for the response...It's giving the output that i wanted...

I have some more questions.
I'm still in learning stage.Please be patient.
Are there lists in DOS?If yes how to use them?
how to append an element to the list?
is there any way to remove an element from a list?


Discussion

No Comment Found