473,466 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Check directory exists c++

1 New Member
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?




Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <dirent.h>
  3.  
  4. bool DirectoryExists( const char* pzPath )
  5. {
  6.     if ( pzPath == NULL) return false;
  7.  
  8.     DIR *pDir;
  9.     bool bExists = false;
  10.  
  11.     pDir = opendir (pzPath);
  12.  
  13.     if (pDir != NULL)
  14.     {
  15.         bExists = true;    
  16.         (void) closedir (pDir);
  17.     }
  18.  
  19.     return bExists;
  20. }
  21.  
  22.  
Jan 5 '07 #1
0 24450

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: calca77 | last post by:
Hi, Please, could anyone tell me how to check if a directory exists. Thank you everyone. D.
1
by: Pgar | last post by:
I have a page that I have the users uploading files from their local machines. I take these files strip off their path and redirect it to a new file on the web server. I have a virtual directory...
1
by: Steven J. Reed | last post by:
I am trying to find out is a folder exists within a share on a server. I can successfully determine if a file exists within the share, but I can't figure out how to determine if it's parent folder...
2
by: Joris De Groote | last post by:
Hi How can I check if a directory exists in a network drive? I can check it on the local machine, but when I want to check a network drive, that doenst work, how can I do this? Thanks Joris
2
by: CCLeasing | last post by:
If (Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" + comOffice.Text + @"\" + numTerm.Value.ToString())) { storereport(); } else { Directory.CreateDirectory(@"c:\indigo\" + txtOfficial +...
9
by: shughes | last post by:
i am not really a programmer, so i have a question on the system.io.directory.exists what i am trying to do is have a button, once this button is clicked it checks to see if the Directory...
1
by: aine_canby | last post by:
Hi, How do I check if a directory exists within another directory? For example C:/aaa C:/Aaa = true C:/aaa/ C:/Aaa/bb = true C:/aaa/ C:/Aaa/bb/cc = true C:/bb/ C:/aa/ = false
0
by: emp | last post by:
I am writing a logging function. Hourly a log entry is made into a directory for the current date. Each day a new current date directory is made. How can I check to see if a directory exists?...
4
by: ndedhia1 | last post by:
Hi. I am writing a java program in which I want to ftp a file to another unix box. First I have to check if the directory exists in which I am ftping into and if it does not exist, I have to create...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.