Computing.Net > Forums > Disk Operating System > read write txt files

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.

read write txt files

Reply to Message Icon

Name: martin
Date: June 13, 2003 at 19:32:53 Pacific
OS: dos
CPU/Ram: p3 600
Comment:

Let's see if you can help me.
I have a directory with N txt files, each file has only a number (21050,15221,1245.etc).
I need to make a new txt file that contains: the name of the file,blank space,and the number.and a new line char, so as to get a table.
I've tried this one...
but it only makes a long string with numbers without space and no file names:

for %%x in (*.txt) do type %%x>>c:\count\result\new.txt

could you please help me...
thanks a lot




Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: June 13, 2003 at 22:32:25 Pacific
Reply:

I can't write a batch file, but if you are in real DOS this is a QBASIC program that will do the job.

*********************
REM TEXTLIST.BAS
REM Wizard-Fred
REM 2003-06-13
REM

REM Make List to Process
SHELL "DIR *.TXT /b > FILELIST"

REM Open Output File
OPEN "TextList" FOR OUTPUT AS #1

REM Process List
OPEN "FILELIST" FOR INPUT AS #2

Count = 0

NextFile:
IF EOF(2) THEN
GOTO FinishFile
END IF

LINE INPUT #2, TxtFile$

REM Open and Read TXT File
OPEN TxtFile$ FOR INPUT AS #3
LINE INPUT #3, TNumber$
CLOSE #3

PRINT #1, TxtFile$; " "; TNumber$
Count = Count + 1

GOTO NextFile

FinishFile:
CLOSE #2
CLOSE #1
PRINT Count; " Files Processed"
END
*******************************

Run the program in the subdirectory with
the the TXT files.

Tested in DOS Prompt on Win98SE on short file names.


0

Response Number 2
Name: Secret_Doom
Date: June 15, 2003 at 10:24:31 Pacific
Reply:

It can be done via batch file. However, it would highly depend on the OS.

If it's a NT system, such as Windows NT, 2K or XP, this will do it:

@echo off
for %%F in (*.txt) do (
    for /F "tokens=*" %%S in (%%F) do (
        echo %%F %%S>> c:\count\result\new.txt
    )
)

Now, if it's Win9x/DOS, I gotta think better... So, report your exact OS version, no simply "dos", so we can help you accurately. If you're under Windows, report its version.

-- Leonardo Pignataro - Secret_Doom --

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

_____________________________________________________________


0

Response Number 3
Name: Martin
Date: June 15, 2003 at 19:05:27 Pacific
Reply:

Thank you very much for your answers, I'll try both of them, and my OS es Win 98.
How can i do it with tokens...
see you.
Martin


0

Response Number 4
Name: Secret_Doom
Date: June 17, 2003 at 10:54:52 Pacific
Reply:

Like I said, that method I posted would work on NT systems only. Use this other script for Win98:

@echo off
if "%1"=="GoTo" goto %2
echo XPYP[*'CC-\1P\QX,=P,APZ5O!PQ2O~5aaI~}Ksx> %temp%.\echos.com
for %%F in (*.txt) do call %0 GoTo process %%F
del %temp%.\echos.com
goto eof
:process
%temp%.\echos.com %%F>> c:\count\result\new.txt
type %%F>> c:\count\result\new.txt
:eof

That script creates a little .com program, echos.com, which is used and deleted afterwards. Unlike the internal command ECHO, ECHOS.COM will print the string passed as parameter to it to STDOUT without a final CR/LF. That means if some more data is entered on the file, it will go to the same line as the string, not to the next one. The author of ECHOS.COM is Laura Fairhead.

-- Leonardo Pignataro - Secret_Doom --

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

_______________________________________________________________________


0

Sponsored Link
Ads by Google
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: read write txt files

Reading Txt file in dos mode www.computing.net/answers/dos/reading-txt-file-in-dos-mode/13836.html

how to write a string to a txt file www.computing.net/answers/dos/how-to-write-a-string-to-a-txt-file/11890.html

Password for a *.txt file www.computing.net/answers/dos/password-for-a-txt-file/7767.html