delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/16/15:47:34

From: "F.X.Gruber-Museum-Arnsdorf" <f DOT x DOT gruber-museum-arnsdorf AT magnet DOT at>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Filename snooping with DJGPP
Date: Mon, 16 Mar 1998 20:16:25 +0100
Organization: magnet Internet Services
Lines: 86
Message-ID: <6ejutb$n7e$1@orudios.magnet.at>
References: <350D321D DOT 70469665 AT cyberstation DOT ca>
NNTP-Posting-Host: 195.3.67.101
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Will Fong schrieb in Nachricht <350D321D DOT 70469665 AT cyberstation DOT ca>...
>Greetings everyone,
>
>    Although I'm not entirely new to C, I'm still a novice, so please
>excuse me. :(
>
>    In DJGPP (running on a DOS/Win95 platform), is there a way to change
>directories?  And when in the directory, to determine all the file names
>in that directory and store just
>the filenames to an array?
>
>thanks in advance,
>Will
>

=============================
Hi, this is out of the djgpp libc .inf file:
=============================
=============================

chdir
=====
Syntax
------
     #include <unistd.h>
     int chdir(const char *new_directory);
Description
-----------
This function changes the current directory to NEW_DIRECTORY.  If a
drive letter is specified, the current directory for that drive is
changed and the current disk is set to that drive, else the current
directory for the current drive is changed.

Return Value
------------
Zero if the new directory exists,
Example
-------
     if (chdir("/tmp"))
       perror("/tmp");

readdir
=======
Syntax
------
     #include <dirent.h>
     struct dirent *readdir(DIR *dir);
Description
-----------
This function reads entries from a directory opened by `opendir' (
opendir::.).  It returns the information in a static buffer with this
format:
     struct dirent {
       unsigned short d_namlen;  /* The length of the name (like strlen) */
       char d_name[MAXNAMLEN+1]; /* The name */
     };
Return Value
------------
A pointer to a static buffer that is overridden with each call.
Example
-------
     DIR *d = opendir(".");
     struct dirent *de;
     while (de = readdir(d))
       puts(de->d_name);
     closedir(d);


===================================================
===================================================
this is me again:

the function "chdir" lets you change the current directory,
and "opendir/readdir/closedir" lets you read the filenames.

Try to compile the examples.
The one of readdir should do more/less the same as DOS's DIR-command.
To save the names to an array, use "strcpy" instead of "puts".

if you need more explaining, send me an email.

Li (=Elias Pschernig)



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019