By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,486 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,486 IT Pros & Developers. It's quick & easy.

File system in linux

P: n/a
Hi,

how to get the file list of current directory or a directory in C
functions?
and how do I change current dir in C?

Thanks,
Daniel

Nov 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
da************@gmail.com a écrit :
how to get the file list of current directory or a directory in C
functions?
There is no standard way. The most portable is the POSIX way :
opendir(), readdir() etc.
and how do I change current dir in C?


Ditto. I can't recall the name of the POSIX way... See the POSIX
documentation on line.

http://www.unix.org/version3/ieee_std.html

--
A+

Emmanuel Delahaye
Nov 20 '05 #2

P: n/a
#include <unistd.h>

char *getcwd(char *buf, size_t size);
char *get_current_dir_name(void);
char *getwd(char *buf);

#include <unistd.h>

char *getcwd(char *buf, size_t size);
char *get_current_dir_name(void);
char *getwd(char *buf);

Nov 21 '05 #3

P: n/a
Richard.C wrote:

What are you talking about? I certainly have no idea since I can't see
what you are replying to.

Please leave in some context so that people can see what you are
replying to if you are going to post replies to comp.lang.c. Search
comp.lang.c for the terms Google and context for instructions on how to
do this.
#include <unistd.h>
This header is not part of standard C and is therefor off topic in
comp.lang.c, so if you want to talk about it please keep the discussion
off comp.lang.c
char *getcwd(char *buf, size_t size);
char *get_current_dir_name(void);
char *getwd(char *buf);
Perfectly acceptable prototypes for use in a C program. Your point is?
#include <unistd.h>

char *getcwd(char *buf, size_t size);
char *get_current_dir_name(void);
char *getwd(char *buf);


I heard you the first time, no need to repeat yourself.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 21 '05 #4

P: n/a
find current dir :

#include <unistd.h>
char *getcwd(char *buf , size_t size);

change dir :

#include <unistd.h>
int chdir(const char *path);
int fchdir(int fd);

make or remove dir :

#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
int mkdir(const char *pathname,mode_t mode);
int rmdir(const char *pathname);

get dir list :

#include <dirent.h>
#include <sys/types.h>
DIR *opendir(const char *pathname);
struct dirent *readdir(DIR *dir);
int rewindir(DIR *dir);
int closedir(DIR *dir);

notice:each readdir call ,like getchar() in read file , point to the
next sub dir . and to get filename use dirent.d_name[] ,it return the
pointer of file name.

Nov 21 '05 #5

P: n/a
marsarden wrote:

If posting, or cross-porting to comp.lang.c please provide context.
Search comp.lang.c for "google context" for instructions.
find current dir :

#include <unistd.h>


<snip>

All this stuff is system specific. Please do NOT post system specific
questions or answers to comp.lang.c since we only deal with standard,
portable C (POSIX is not the C standard, and not portable to everywhere,
so being POSIX does not count).

I made BOTH of these requests in the post you are replying to, and I
said "please" in both, so you can't be ignoring it because I was
impolite, it can't be because you don't speak English, since your reply
is in English, so it must be because *you* are impolite.

FU set to exclude comp.lang.c
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 21 '05 #6

P: n/a
Simply include stdlib.h header and use system("ls");

Nov 21 '05 #7

P: n/a
> Simply include stdlib.h header and use system("ls");

....Eww, no, _don't_ do that!
Nov 21 '05 #8

P: n/a
Thank you for your advice!

But, plz notice the TOPIC IS :"File system in linux". NOT " how
tocurrent directory or a directory in C functions".

Nov 23 '05 #9

P: n/a
Richard.C wrote:
Thank you for your advice!
and thank *you* for ignoring multiple requests to take the *off*
comp.lang.c!
But, plz notice the TOPIC IS :"File system in linux". NOT " how
tocurrent directory or a directory in C functions".


This is COMPLETELY OFF TOPIC in comp.lang.c, so keep it ONLY on the
linux group.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 23 '05 #10

P: n/a
Thank you, that helped a lot!

Nov 23 '05 #11

P: n/a
Richard.C <cy@microembed.cn> wrote:
Thank you for your advice!

But, plz notice the TOPIC IS :"File system in linux". NOT " how
tocurrent directory or a directory in C functions".


That simply makes the question off topic to CLC.

Deleted followup-to mlist.linux.c-programming, cause discussions about
topicality in CLC are off topis there. ;-0

--
Z (zo**********@web.de)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
Nov 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.