473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

File system in linux

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
11 3385
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
#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
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
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
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
Simply include stdlib.h header and use system("ls");

Nov 21 '05 #7
> Simply include stdlib.h header and use system("ls");

....Eww, no, _don't_ do that!
Nov 21 '05 #8
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
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
Thank you, that helped a lot!

Nov 23 '05 #11
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of...
6
by: o'seally | last post by:
solaris/linux admins/rookie_developers that battle with this error are probably all frustrated when it happens. i bet you're also somehow frustrated by this seemingly unsolvable error :-) ...take...
10
by: John Ratliff | last post by:
What is the best way to determine a file's size? Should I use stat? Is this a better way? std::fstream file("myfile", std::ios_base::in | std::ios_base::binary); file.seekg(0,...
17
by: Carmen Wai | last post by:
Hello: I would like to know whether there is any different in installing Postgresql on the Linux system with file system of EXT2 or EXT3. I have two machines with idential OS (Red Hat 7.3...
10
by: ken | last post by:
hello, i'm writing a c program on a linux system. i'm debugging a segmentation fault but i don't want it to dump a core file because the memory footprint of the program is over 300Mb and i don't...
7
by: clusardi2k | last post by:
Hello, I have a shared drive on SGI, Linux, and Windows. A second call to fopen doesn't create the file if it has been deleted. I would like to use fopen for its pointer return value to...
5
by: sc48567189 | last post by:
Hello ! I need some help here. I google after the response but with no sucess. I need to download - randon size - parts of a file, not the whole file. Says: I have the zip file test.zip, it is 10...
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
8
by: Richard | last post by:
"Bill Cunningham" <nospam@nspam.invalidwrites: By stdc do you mean "standard c" Bill? I think you should ask in c.l.c : they are always willing to help people with their parsers and 128...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.