Mail Archives: djgpp/1998/03/16/15:47:34
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 -