473,320 Members | 2,052 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,320 software developers and data experts.

How do I check for directory existence in Linux?

I wasn't sure if this should go in a linux group or the C group, but
here I am.

How do I check for directory existence in C? It's gcc under Linux to
be exact, and I don't have the option of just making it to ensure that
it's there.

Thanks.
Hector

Nov 15 '05 #1
6 13603
<he*******@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
How do I check for directory existence in C? It's gcc under Linux to
be exact, and I don't have the option of just making it to ensure that
it's there.


This is a bit OT in this group since directory I/O is beyond the scope of
the standard C library, but you may consider using opendir(), closedir(),
readdir(). Download and use The Single UNIX Specification, it's free
somewhere on the net. Or use man.

Alex
Nov 15 '05 #2
he*******@yahoo.com writes:
I wasn't sure if this should go in a linux group or the C group, but
here I am.

How do I check for directory existence in C? It's gcc under Linux to
be exact, and I don't have the option of just making it to ensure that
it's there.


Definitely a Linux or Unix group, probably comp.unix.programmer.
Standard C has no concept of directories.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #3
In article <11**********************@z14g2000cwz.googlegroups .com>,
<he*******@yahoo.com> wrote:

I wasn't sure if this should go in a linux group or the C group, but
here I am.

How do I check for directory existence in C? It's gcc under Linux to
be exact, and I don't have the option of just making it to ensure that
it's there.


There are posix-specific functions that will let you do
that directly. opendir/readdir and stat come to mind.
But pure C itself doesn't really have any directory-related
functions.

A partial hack is to try to open a file in the directory.

If you can open a file in the directory, then the
directory must exist. However the converse is not
always true: if you cannot open the file, it may be
for other reasons like access permission, disk full,
running out of file descriptors, all kinds of stuff.
Nov 15 '05 #4
Sorry about the ot. I actually wised up right after posting (of
course) and used a chdir() error condition to see if it exists.

Nov 15 '05 #5
Sorry about the ot. I actually wised up right after posting (of
course) and used a chdir() error condition to see if it exists.

Nov 15 '05 #6
he*******@yahoo.com wrote:
Sorry about the ot. I actually wised up right after posting (of
course) and used a chdir() error condition to see if it exists.


man 2 stat, since chdir() does change the working dir if it succeeds.
Igmar
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
2
by: David | last post by:
I'm using following code for checking a file existence. I's working fine for given folder. Is there a way to check a file exitance in subfolders? Thanks in advance, David Option Compare...
32
by: deko | last post by:
I'm trying to create an MSI in VS.NET that will check for installed Office System components - so my MDE will only install if requirements are met. I'm thinking about using VBScript to inspect...
9
by: minil | last post by:
Hi any c function in linux to return size of directory (Including its files & subdirectories & its files).. I can stat() only files . not for directories. please reply me soon Thanks in...
10
by: Ricardo Luceac | last post by:
Hi all. I'm having a problem with this, I have look if a file exists, if don't wait till it is created and if it exists I need to open it. I do the following: for (; ; ) {
2
by: www.MessageMazes.com | last post by:
Greetings, I'm experimenting with an ASP page that reads data from a file name that is passed to it as a parameter, as in this page, which works, because the "good" file exists. ...
5
by: Gary Wessle | last post by:
hi or is there a better way to check the existence of "py" in a string "s"? string s = "djrfpyfd"; string t = "py"; string r = s.substr(s.find("py"),2); cout << (t==r) << endl;
0
by: ramith | last post by:
Guys, I wrote a simple code to check the existence of a directory (in UNIX based file systems) which is working for me. Have I done it in the correct way? #include <dirent.h>
10
by: Dieter Pelz | last post by:
Hallo, what is the best way to check the installation of mfc80 and vcrt sidebyside assemblies? Best Regards, Dieter Pelz
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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...

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.