Scanning for sub-directories with TP7 
Author Message
 Scanning for sub-directories with TP7

Yo, anyone know how to program a piece of code that would scan an entire HD
of its directories contents ?
Something like "DIR /S", except I dont want to use the EXEC command, that
is for cheaters, I tried to get the commands FindFirst & FindNext to do
this... but they only do locals. Do I have to program some hot-shot
algorithm to do this or is there an easier way out of this ? Since I am not
a hot shot, I was hoping some other already educated Top-down approach guy
would like to help an Bottom-up approach guy to get it right! ( if ya know
what I am talking about here. I saw a similar example in a windows unit /
prog but, needless to say the code / example was very difficult to extract
from a windows pas file...

hope someone got some interest ?

Cheers
Gustaaf  



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7


Quote:
>Yo, anyone know how to program a piece of code that would scan an entire HD
>of its directories contents ?
>Something like "DIR /S", except I dont want to use the EXEC command, that
>is for cheaters, I tried to get the commands FindFirst & FindNext to do
>this... but they only do locals. Do I have to program some hot-shot
>algorithm to do this or is there an easier way out of this ?

[...]

My guess is the procedure you have to search local directories
could be made to do the job.  If it doesn't receive the path
to the directory to be searched, modify it so that it does.
Then have it search attributes for anyfile.  Test the
attributes for each "found" value and have it call itself with
the new path if a directory, else process the entry as you
normally would.

    ...red

--
Support the anti-Spam amendment
  Join at http://www.cauce.org/



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7



Quote:

>uses dos, crt;

Why Crt?

Quote:

>var
>  stack : word;

>procedure listall (root : string);

Since there is a maximum limit for paths it is better to avoid stack
usage by using pathstr. Also it is good just to provide the directory
and not the '*.*'. That way one does not need strings for splitting the
name. Sure one could write a more versatile version that allowed things
like "*.BAK" but in that case one should process the directories with a
separate search (with *.*). Your code works only with "directory\*.*"
type of arguments.  Even in the more versatile version one should pass
directory and mask separately to avoid splitting.

Quote:
>var
>  fi : searchrec;
>  d : dirstr;
>  n : namestr;
>  e : extstr;

>begin
>  if SPtr<stack then
>    stack := SPtr;
>  root := fexpand (root);
>  findfirst (root, anyfile, fi);
>  fsplit (root,d,n,e);
>  while doserror=0 do
>    begin
>      if ((fi.attr and directory)=directory) and (fi.name<>'.')
>         and (fi.name<>'..') then

if (fi.attr and directory >0) and (fi.name[1]<>'.') does the trick nicely.

- Show quoted text -

Quote:
>           begin
>             writeln (d,fi.name);
>             listall (d+fi.name+'\*.*');
>           end
>      else
>        writeln (d+fi.name);
>      findnext (fi);
>    end;
>end;

>begin
>  stack := SPtr;
>  listall ('C:\*.*');
>  writeln ('Mimimum stack left:  ',stack);
>end.

>> Cheers
>> Gustaaf

>--
>Scott Earnest        | We now return you to our regularly |


Osmo


Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

Quote:



> >uses dos, crt;

> Why Crt?

Only for the sake of speeding display output.  This was just something I
made for experimental projects.  It's not any polished gem or well-tuned
algorithm.

Quote:

> >var
> >  stack : word;

> >procedure listall (root : string);

> Since there is a maximum limit for paths it is better to avoid stack
> usage by using pathstr. Also it is good just to provide the directory
> and not the '*.*'. That way one does not need strings for splitting the
> name. Sure one could write a more versatile version that allowed things
> like "*.BAK" but in that case one should process the directories with a
> separate search (with *.*). Your code works only with "directory\*.*"
> type of arguments.  Even in the more versatile version one should pass
> directory and mask separately to avoid splitting.

True.  But again, it's a kludge, not an ultimate solution.  :-)

Quote:
> >var
> >  fi : searchrec;
> >  d : dirstr;
> >  n : namestr;
> >  e : extstr;

> >begin
> >  if SPtr<stack then
> >    stack := SPtr;
> >  root := fexpand (root);
> >  findfirst (root, anyfile, fi);
> >  fsplit (root,d,n,e);
> >  while doserror=0 do
> >    begin
> >      if ((fi.attr and directory)=directory) and (fi.name<>'.')
> >         and (fi.name<>'..') then

> if (fi.attr and directory >0) and (fi.name[1]<>'.') does the trick nicely.

Hmm, I'm surprised I let that slip, even the first time around.  :-)

Quote:
> Osmo

--
Scott Earnest        | We now return you to our regularly |



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

Quote:



> >uses dos, crt;

> Why Crt?

Dumb question, why not? Is there something wrong with it?

--
- Asbj?rn / Lord Crc

http://home.sn.no/~bheid/



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

Quote:




> > >uses dos, crt;

> > Why Crt?

> Dumb question, why not? Is there something wrong with it?

> --
> - Asbj?rn / Lord Crc

> http://home.sn.no/~bheid/


I heard once, the Pentiom-II (very new, from INTeL) has problems with
the so-called "DELAY" procedure, and something else that will prevent a
program that uses CRT from running. Didn't tested it, 'couse I'm happy
with my P-133 in DOS ;)




Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7



:
: Sorry to interrupt, but I did the above version and found out the
: following:
:
: What if a Directory with name ".XY" exists? I don't know if DOS usually
: allows it, but I had this case once! With your solution this won't be
: scanned (is I got this code frag. right)
:

:

Well you could make yore program to support "*.* & "????????.???". I have
done this in my own prog, and it does find weird directory names, even
directory names with spaces in them!

Hope that was of some assist ?

Cheers
Gustaaf



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

Quote:
> > >      if ((fi.attr and directory)=directory) and (fi.name<>'.')
> > >         and (fi.name<>'..') then

> > if (fi.attr and directory >0) and (fi.name[1]<>'.') does the trick nicely.

Sorry to interrupt, but I did the above version and found out the
following:

What if a Directory with name ".XY" exists? I don't know if DOS usually
allows it, but I had this case once! With your solution this won't be
scanned (is I got this code frag. right)




Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

On Mon, 11 Aug 1997 20:15:08 +0200, Gruber Roman

Quote:

>What if a Directory with name ".XY" exists? I don't know if DOS usually
>allows it, but I had this case once! With your solution this won't be
>scanned (is I got this code frag. right)

In DOS, the "directory placement back path" of the directory tree is
defined by a directory with the name of "." (yes that's a directory
name with one period, it's not 8 spaces a period and 3 spaces, it's
just a period in the first position).  It is used internally for DOS,
otherwise it's completely worthless in terms of text processing.

Quote:
> > >      if ((fi.attr and directory)=directory) and (fi.name<>'.')
> > >         and (fi.name<>'..') then

> > if (fi.attr and directory >0) and (fi.name[1]<>'.') does the trick nicely.

Note, though, that you may wish to display the directory which also
exists by the name of "..", which is used by DOS to "find it's way
back out" of the current directory.  This directory would be very good
to have in some situations.

Your directory name example, ".XY" will function properly
nonetheless..



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

Quote:

> > > >      if ((fi.attr and directory)=directory) and (fi.name<>'.')
> > > >         and (fi.name<>'..') then

> > > if (fi.attr and directory >0) and (fi.name[1]<>'.') does the trick nicely.

> Sorry to interrupt, but I did the above version and found out the
> following:

> What if a Directory with name ".XY" exists? I don't know if DOS usually
> allows it, but I had this case once! With your solution this won't be
> scanned (is I got this code frag. right)

*IF* you have a directory named .XY, there are probably two
possibilities, either:  1.) Your directory entry is trashed and contains
illegal characters (it *is* possible to directly modify a directory
entry to enter a file name like ".XY", [ASCII 46/88/89] in the file
name, but DOS would have trouble with it in any case).  2.)  You created
a directory with this name in Win 95.  It's stored as a long file name,
and the findfirst procedure would acknowledge it as "xy~1" anyway.

--
Scott Earnest        | We now return you to our regularly |



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

[comp.os.msdos.programmer added]

Quote:

> > > >      if ((fi.attr and directory)=directory) and (fi.name<>'.')
> > > >         and (fi.name<>'..') then

> > > if (fi.attr and directory >0) and (fi.name[1]<>'.')
> > > does the trick nicely.

> Sorry to interrupt, but I did the above version and found out the
> following:

> What if a Directory with name ".XY" exists? I don't know if DOS usually
> allows it,

Plain DOS (and even Windows 95) don't.

I don't know what do NFS products when connected with a UNIX server
that use these names, though.

Quote:
> but I had this case once!

Can you explain how you construct it?

Thanks in advance

Antoine



Wed, 18 Jun 1902 08:00:00 GMT  
 Scanning for sub-directories with TP7

Quote:

> [comp.os.msdos.programmer added]

> > What if a Directory with name ".XY" exists? I don't know if DOS usually
> > allows it,

> Plain DOS (and even Windows 95) don't.

As I mentioned earlier in the thread, Windows 95 *does* allow a
directory with this name -- with the catch being that it's stored as an
LFN.  The 8.3 file name will be "XY~1".

Quote:
> I don't know what do NFS products when connected with a UNIX server
> that use these names, though.

In Unix, "." at the beginning of a file name indicates a file that is
hidden, and requires the -a flag on an ls command to be seen in the
directory listing.

Quote:
> > but I had this case once!

> Can you explain how you construct it?

I'm at a loss too.  The only way I could think of, is to do MD "AAA",
then edit the directory in a sector editor like Norton Disk Edit,
directly change "AAA" to ".XY", then save.  Of course, if you run
ScanDisk or Norton Disk Doctor, it's likely to complain about a
directory with invalid characters, and attempt to fix it.  Until it's
fixed, I'm not sure you'd have a directory you'd be able to CD to or
make use of.  I can't test it now because I don't have Norton for Win 95
yet.

Quote:
> Thanks in advance

> Antoine

--
Scott Earnest        | We now return you to our regularly |



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Scanning for sub-directories with TP7

2. hunt.zip Scan sub/directories + commands, w/TP src

3. How Copy 1 Directory with Sub Directory

4. listing sub directories....

5. Running sub-programs in TP6/TP7 programs

6. How do I implement sub sub filters ??

7. Directory Tree in TP7

8. how can I list all sub-directories on a hard drive?

9. how can I list all sub-directories on a hard drive?

10. How do I scan the my Harddisk for a directory?

11. how to use void as a sub function?

12. Sub Query is Sooooooo Sloooooow (D2/W95/Paradox7)

 

 
Powered by phpBB® Forum Software