Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

DOS utility to display 1st line of all files in directory? (Users)

posted by Rugxulo Homepage, Usono, 19.12.2012, 20:44
(edited by Rugxulo on 20.12.2012, 21:06)

> Thanks Rugxulo!
>
> I'm going to take your batch file (see below) for a spin.
>
> I don't have QBasic installed on my computer, so I figure I'll have to try
> to find it on an old floppy and install it before your file will work;
> right? (What do I need to do besides copying the QBasic files to a
> directory and adding the directory to my path?).

I had thought QBASIC (QBASIC.EXE, QBASIC.HLP) was always installed. But maybe they only put it in "SUPP" (Supplement) add-on, I forget. That was my whole point, you wouldn't have to install anything extra! :-)

> In the meantime, will your batch file look at the first line of all
> files in a directory, not just the ones with .txt extension?

It probably won't work except for normal and readonly attribute files. But you can temporarily use Attrib to workaround that. If you need more than "*.txt", you'll have to change that to whatever else you want. If you need more than one extension, you may have to have another .BAT file "call" this one:


@echo off
REM ... There are tricker ways, but this will do in a pinch ...
for %%a in (*.aaa) do call oneline.bat %%a
for %%a in (*.bbb) do call oneline.bat %%a
for %%a in (*.ccc) do call oneline.bat %%a


> I use an
> alpha/numeric code for the three character file extensions as a way of
> tagging files.

In other words, "*.*" won't work because other non-text files are also present? As a silly workaround, you could probably "Attrib +H" those particular files, and then it would ignore them.

> Also, could I add a routine to your batch file so that it would sort the
> first lines into alpha/numeric order?

You mean sort the output of the ONELINE.BAT file? You may have to create an OUTER.BAT file first (as redirection within a nested FOR command doesn't always do what you'd expect):


@echo off
REM outer.bat
for %%a in (*.txt) do call oneline.bat %%a


Then do this:

C:\TMP> REM echo %%COMSPEC%% = %COMSPEC% (DOS 6 shell doesn't support env.var. expansion at cmdline)
C:\TMP> command /c outer.bat | sort

 

Complete thread:

Back to the forum
Board view  Mix view
22762 Postings in 2122 Threads, 402 registered users (1 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum