How to output a list to a line?

K

Kevin Brault

Hello everyone,

I am not sure is this is the correct place to post this ....

In Windows XP I have a need to take the output of "dir /b *" and place it on one line with quotes around each file name and a space between them.

So ....

file 1.ext
file 2.ext
file 3.ext

Would end up as:

"file 1.ext" "file 2.ext" "file 3.ext"

I was thinking of a "for" loop and the "set" command but am over my head.

Would anyone be able to get me started?

Thank you in advance for your help.

Kevin
 
P

Pegasus \(MVP\)

Hello everyone,

I am not sure is this is the correct place to post this ....

In Windows XP I have a need to take the output of "dir /b *" and place it on
one line with quotes around each file name and a space between them.

So ....

file 1.ext
file 2.ext
file 3.ext

Would end up as:

"file 1.ext" "file 2.ext" "file 3.ext"

I was thinking of a "for" loop and the "set" command but am over my head.

Would anyone be able to get me started?

Thank you in advance for your help.

Kevin

=======

Try this:
@echo off
SetLocal EnableDelayedExpansion
set Line=
for %%a in (*.*) do set Line="%%a" !Line!
echo %Line%
 
M

Matthias Tacke

Kevin said:
Hello everyone,

I am not sure is this is the correct place to post this ....

In Windows XP I have a need to take the output of "dir /b *" and place
it on one line with quotes around each file name and a space between them.
@echo off
for /f "delims=" %%A in ('dir /B *') do set /P _= "%%~A" <NUL
 
A

Al Dunbar

Pegasus (MVP) said:
Hello everyone,

I am not sure is this is the correct place to post this ....

In Windows XP I have a need to take the output of "dir /b *" and place it
on one line with quotes around each file name and a space between them.

So ....

file 1.ext
file 2.ext
file 3.ext

Would end up as:

"file 1.ext" "file 2.ext" "file 3.ext"

I was thinking of a "for" loop and the "set" command but am over my head.

Would anyone be able to get me started?

Thank you in advance for your help.

Kevin

=======

Try this:
@echo off
SetLocal EnableDelayedExpansion
set Line=
for %%a in (*.*) do set Line="%%a" !Line!
echo %Line%

or this:

@echo off
SetLocal EnableDelayedExpansion
set Line=
for %%a in (*.*) do (set Line=!Line! "%%a")
(set line=%line:~1%)
echo/[%Line%]

this puts the files in the same order they are emitted by the FOR statement,
and ensures that no additional blank characters are present in the output.

/Al
 
T

Tom Lavedas

Hello everyone,

I am not sure is this is the correct place to post this ....

In Windows XP I have a need to take the output of "dir /b *" and place iton one line with quotes around each file name and a space between them.

So ....

    file 1.ext
    file 2.ext
    file 3.ext

Would end up as:

    "file 1.ext" "file 2.ext" "file 3.ext"

I was thinking of a "for" loop and the "set" command but am over my head.

Would anyone be able to get me started?

Thank you in advance for your help.

Kevin

I think you want something like this ...

set "line="
for %%a in (*.ext) do (call set line=%%line%%"%%a" )
echo %line%

It finds all of the files that match the extension, encloses them in
double quotes and places them all on one line of test. To output this
to a file, redirect the ECHO line into the desired file name ...

echo %line%>outfilename.txt

To use a more focused search for the files, modify the wildcard
filespec in the FOR. For example, to find files with a name, say FILE
having one addition character, use ...

for %%a in (file?.ext) do ...

BTW, for long lists, this approach may breakdown. I think there is
still a 1024 character limit on the lengths of command lines in batch
procedures.

HTH,

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
 
K

Kevin Brault

Thanks Pegasus, Al,

SetLocal EnableDelayedExpansion
set Line=
for %%a in (*.*) do (set Line=!Line! "%%a")

Was exactly what I wanted.
This group is great!

Kevin




Pegasus (MVP) said:
Hello everyone,

I am not sure is this is the correct place to post this ....

In Windows XP I have a need to take the output of "dir /b *" and place it
on one line with quotes around each file name and a space between them.

So ....

file 1.ext
file 2.ext
file 3.ext

Would end up as:

"file 1.ext" "file 2.ext" "file 3.ext"

I was thinking of a "for" loop and the "set" command but am over my head.

Would anyone be able to get me started?

Thank you in advance for your help.

Kevin

=======

Try this:
@echo off
SetLocal EnableDelayedExpansion
set Line=
for %%a in (*.*) do set Line="%%a" !Line!
echo %Line%

or this:

@echo off
SetLocal EnableDelayedExpansion
set Line=
for %%a in (*.*) do (set Line=!Line! "%%a")
(set line=%line:~1%)
echo/[%Line%]

this puts the files in the same order they are emitted by the FOR statement,
and ensures that no additional blank characters are present in the output.

/Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top