LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-10-2007, 06:00 AM   #1
jaepi
Member
 
Registered: Apr 2007
Location: Urban Jungle
Distribution: Ubuntu
Posts: 189
Blog Entries: 1

Rep: Reputation: 30
check if directory exist


how would you check if the directory already exist using c++???help pls..
 
Old 05-10-2007, 07:41 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
access(), stat().
 
Old 05-10-2007, 08:10 AM   #3
jaepi
Member
 
Registered: Apr 2007
Location: Urban Jungle
Distribution: Ubuntu
Posts: 189

Original Poster
Blog Entries: 1

Rep: Reputation: 30
Quote:
Originally Posted by jim mcnamara
access(), stat().
dude, can you pls elaborate by giving an example...i viewed the man page and tried it to the cli, it has no response T_T
 
Old 05-10-2007, 08:59 AM   #4
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
"The existence test, F_OK".


PHP Code:
status=access("/etc/fstab1",F_OK);

if(
status==-1)
{
    
//doesn't exist OR uid doesn't have permission
}
else
{
    
//ok

Hope I got this right. Cheers.
 
Old 05-10-2007, 08:53 PM   #5
jaepi
Member
 
Registered: Apr 2007
Location: Urban Jungle
Distribution: Ubuntu
Posts: 189

Original Poster
Blog Entries: 1

Rep: Reputation: 30
Quote:
Originally Posted by nc3b
"The existence test, F_OK".


PHP Code:
status=access("/etc/fstab1",F_OK);

if(
status==-1)
{
    
//doesn't exist OR uid doesn't have permission
}
else
{
    
//ok

Hope I got this right. Cheers.
thanks dude...
 
Old 05-10-2007, 09:27 PM   #6
jaepi
Member
 
Registered: Apr 2007
Location: Urban Jungle
Distribution: Ubuntu
Posts: 189

Original Poster
Blog Entries: 1

Rep: Reputation: 30
btw, what do i include??
#include <??>
 
Old 05-10-2007, 09:45 PM   #7
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Dude - the man page *tells* you what headers you should include!

PS:
I think you should probably acknowledge that Jim McNamara was only trying to help. "access()" and "stat()" are two excellent replies. There are many others, depending on your platform and development environment.

PPS:
If it still doesn't work, please:
a) Cut/paste example code that you wrote (it probably shouldn't be much longer than 4 or 5 lines, tops!)
b) Cut/paste your "build" command line (this will tell us several important facts, including your compiler version)
c) Cut/paste the results of running your program
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if users exist in the system hindll01 Programming 12 09-28-2012 03:24 PM
Check if email exist or not proNick Linux - Software 2 08-27-2005 02:25 PM
How to check if a software exist in my computer Niceman2005 Linux - Newbie 4 12-28-2004 10:12 PM
How to check if array[0] doesn't exist? flamesrock Programming 3 11-05-2004 11:36 AM
script to check $PATH directories exist Frustin Linux - Software 3 09-21-2004 01:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration