[comp.lang.c] Reading MS-DOS directory in C, how to

dkazdan@cwsys2.cwru.edu (David Kazdan) (02/14/90)

Netfolk:

I would like to read the current directory in a C program, but either
the books I have been reading (the Turbo C reference and my library of
beginner's books on the language) don't mention it, or I don't know
where in the index to look.  I assume there's some call that returns
an array of pointers to strings, but I really can't figure it out.

Help much appreciated.  Post or E-mail, as you wish.

73,

David

pingpong@milton.acs.washington.edu (jimmy) (02/14/90)

In article <1990Feb14.031640.28944@usenet.ins.cwru.edu> dkazdan@cwsys2.cwru.edu (David Kazdan) writes:
>
>I would like to read the current directory in a C program, but either

Try : getcwd(string, 80);  /* char string[80]; */

Hope this helps.

Jimmy. 

david@csource.oz.au (david nugent) (02/15/90)

 > Message-ID: <1990Feb14.031640.28944@usenet.ins.cwru.edu>
 >
 > I would like to read the current directory in a C program, but either
 > the books I have been reading (the Turbo C reference and my library of
 > beginner's books on the language) don't mention it, or I don't know
 > where in the index to look.  I assume there's some call that returns
 > an array of pointers to strings, but I really can't figure it out.


Hmm, no.

Turbo C should include a findfirst() and findnext() functions, which allow 
you to pass both a file "specification" and attributes. It's usually done 
something like this (node that the given path can include wildcards):


 .
 .
 #include <dos.h>
 #include <dir.h>
 .
 .
 .
 {
 int j;
 struct ffblk ff;       /* contains directory data */

 j = findfirst ("*.*", &ff, FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_DIREC);
 while (j)
      {
      /* store information or do whatever */
      j = findfirst (&ff);
      }
 .
 .


david

--  
uucp: ...!munnari!csource!david   
internet: david@csource.oz.au
Via FidoNet 3:632/348, Melbourne, Australia.

dlucy@tropez.UUCP (Doug Lucy) (02/15/90)

In article <1990Feb14.031640.28944@usenet.ins.cwru.edu>, dkazdan@cwsys2.cwru.edu (David Kazdan) writes:
> 
> would like to read the current directory in a C program....
> some call that returns an array of pointers to strings
> 

The CXL (C eXtended Library) by Mike Smedley (it's shareware) is a rather
full-featured windowing, input and graphics lib. It has two functions you
may be interested in (not sure what your application is): wpickstr and
wpickfile. These functions put up a user-defined window complete with
highlight bar and user-defined/or-not movement that lets the user pick
a string from an array *OR* pick a filename from the disk structure
(user can follow tree up or down). It comes in Microsoft, Zortech (?) 
and Borland flavors. Lots of docs, too. (Does this sound like an ad,
or what?)

-- 

  "It's such a fine line between clever..."     < Doug Lucy           DC Pro >
  "...and stupid."                              < uucp:   uunet!tropez!dlucy >
  "Yeah, stupid."                               < bbs:          703-370-8672 >

david@csource.oz.au (david nugent) (02/16/90)

 >  j = findfirst ("*.*", &ff, FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_DIREC);
 >  while (j)
 >       {
 >       /* store information or do whatever */
 >       j = findfirst (&ff);
 >       }

A correction:  The while statement above should read:

      while (j == 0)

etc.

Sorry if it caused you any problems.

david

--  
uucp: ...!munnari!csource!david   
internet: david@csource.oz.au
Via FidoNet 3:632/348, Melbourne, Australia.

Bob.Stout@p6.f506.n106.z1.fidonet.org (Bob Stout) (02/17/90)

In an article of <14 Feb 90 03:16:40 GMT>, (David Kazdan) writes:

 >I would like to read the current directory in a [Turbo] C program

This is both OS- and compiler-specific. Check your TC manual for the  
findfirst() and findnext() functions. 

sofmac@porthos.rutgers.edu (Sofus Macskassy) (02/18/90)

In Turbo-C, there is are 2 functions, findfirst and findnext, which
will give you what you need.  They should both be in your Turbo-C
reference guide.  If you are not using turbo-c, similar MS-DOS system
calls can be made.  If you can't find the information in your
reference guide, let me know, and I will give you the proper syntax
for either the C commands, or system calls.

Sofus Macskassy

Roy.Browning@f506.n106.z1.fidonet.org (Roy Browning) (02/19/90)

David:

        On my system (713-350-6284) I have three very small and simple files  
that demonstrate the migration from C to single inheritance C++.  The section  
of the program that obtains the directory is standard C.  The FileNames are  
DL_1.ZIP, DL_2.ZIP, and DL_3.ZIP with the first being the closest to standard  
C.  Note, these programs were designed to help beginners.

                          C++ing a little better,

                              Roy Browning