Computing.Net > Forums > Disk Operating System > Batch: Make list of files on one line

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.

Batch: Make list of files on one line

Reply to Message Icon

Name: Johan
Date: June 19, 2002 at 10:29:10 Pacific
Comment:

  Hi,

I'm trying to make a file or variable that contains a semicolon separated list of files in a dir.

for %%i in (*.jar) do call echo %%i; >> jarlist.txt

or

for %%i in (*.jar) do set CPATH=%CPATH%;%%i

Does not work because echo will add a CR/LF pair and for some strange reason only the last file in the list will be added to CPATH.

Greatful for any help on this.

  Yours, Johan



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: June 19, 2002 at 11:01:45 Pacific
Reply:

On Windows 9x:

The following line will work on the command prompt the way you want:

for %%i in (*.jar) do set CPATH=%%CPATH%%;%%i

But it simply doesn't work onto a batch file, and I couldn't get it working by that way. However, if you want this in a batch file, we can use your first idea, just a little different:

@echo off
if "%1"=="GoTo:" %1%2
SET CPATH=
for %%? in (*.jar) do call %0 GoTo: setvar %%?
goto eof
:setvar
SET CPATH=%CPATH%;%3
:eof

This script could require a big enviroment space, so it's a good idea to run it on a child shell with a big enviroment space:

@echo off
if "%1"=="GoTo:" %1%2
%comspec% /c call %0 GoTo: start
goto eof

:start
SET CPATH=
for %%? in (*.jar) do call %0 GoTo: setvar %%?
echo CPATH=%CPATH%
goto eof
:setvar
SET CPATH=%CPATH%;%3
:eof

After running this last batch script, the CPATH won't have changed. That's because the variables are reset to their original state when a child shell of COMMAND.COM is terminated.

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0
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: Batch: Make list of files on one line

Dir list of files only,no subfolder www.computing.net/answers/dos/dir-list-of-files-onlyno-subfolder/15578.html

List of files www.computing.net/answers/dos/list-of-files/12204.html

How to create a log file in 1 line www.computing.net/answers/dos/how-to-create-a-log-file-in-1-line/12735.html