Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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
REMREM Make List to Process
SHELL "DIR *.TXT /b > FILELIST"REM Open Output File
OPEN "TextList" FOR OUTPUT AS #1REM Process List
OPEN "FILELIST" FOR INPUT AS #2Count = 0
NextFile:
IF EOF(2) THEN
GOTO FinishFile
END IFLINE INPUT #2, TxtFile$
REM Open and Read TXT File
OPEN TxtFile$ FOR INPUT AS #3
LINE INPUT #3, TNumber$
CLOSE #3PRINT #1, TxtFile$; " "; TNumber$
Count = Count + 1GOTO 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.

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_____________________________________________________________

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

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
:eofThat 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_______________________________________________________________________

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |