Posted by Jaz on 1998-03-12
>Could somebody please help me out here.
>I am in urgent need of source for file handling .
>This is what I need it to do.
>
>1). To show only certain files of my choosing. Eg:showfiles('*.txt *.pas
>*.lst *.tpu *.bgi',5, 2,20,24,shadowon)
>2). directories and files to be sorted in alphabetical order.
>3). Tagging abilities.
>4). Text mode.. 80x50
>5). Miniumn of 1024 files per directory.
I have no finished source for you but an instruction how
to do it (I suppose you want it in Pascal?):
First, define a new Record, that contains all the file
data you want to save, for example:
Type MyFileRec = Record
Name: String[11]; {8 + 3 characters}
Size: LongInt;
Tag: Boolean;
End;
Define everything you need, you could add for example
a variable indentifying the Record data as Directory,
File or Disk ID, a variable for file attributes, etc.
Now we want to make an array of "MyFileRec"s containing
the collected data from the hard disk. You could store
the array in the normal memory (you know how to make
arrays with dynamic sizes, a dynamic limit? Tell me if
not), on the hard disk (a bit slower but if you aren't
writing a "every-nanosecond-counts" program this won't
matter if a diskcache like SmartDrive is loaded), or,
if available, in EMS.
Make a procedure
Procedure GetFiles(FileMasks: String);
"FileMasks" should consist of filenames ('*'s are
allowed), e.g. '*.tpu; t*.exe; turbo.*'.
In the GetFiles procedure, just get the files
via the "FindFirst" and "FindNext" procedures in
DOS.TPU for the filemasks defined in "FileMasks"
and write them all in the data array you created.
I think the wildcards function is already
implemented in the FindFirst and FindNext procedures.
All the other procedures shouldn't read anything
from the hard disc any more, they just care of the
data array.
Procedure ShowFiles(X,Y,NameColor,ExtColor,Sizecolor: Byte); {whatever you need for output style}
.. just displays the content of your data array
Procedure SortFiles(SortBy: byte; Ascending: Boolean);
.. sorts the stuff in your data array. The
most simple but slow way of sorting an array is
to check the whole array from 1 to maximum,
search for the "highest" var, exchange it with
the top, check the whole array from 2 to maximum,
exchange the "highest" var with the 2nd position,
etc. Take a look at the "QSORT.PAS" in your
Pascal directory (TP6: "\DEMOS\" TP7: "\EXAMPLES\")
for a faster way.
Jaz
--- luna.kil@xxxxxxx.xxx
=== member of the Coder's Guild:
--- http://www.paracatz.com/codersguild/
Previous post | Next post | Timeline | Home