Computing.Net > Forums > Programming > checking a file exist or not

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

checking a file exist or not

Reply to Message Icon

Original Message
Name: mike
Date: July 26, 2002 at 14:23:39 Pacific
Subject: checking a file exist or not
Comment:

i want to check if a file is exists in a directory or not during runtime in my C++ programme i wrote on solaris

any one knows how that check can be done for unix ? in c++


Report Offensive Message For Removal


Response Number 1
Name: Tom
Date: July 26, 2002 at 21:08:15 Pacific
Reply: (edit)

Just open the file, using ios::nocreate, and if it fails, the file doesn't exist. If it doesn't fail, you can just close the file.


Report Offensive Follow Up For Removal

Response Number 2
Name: cup
Date: July 27, 2002 at 02:54:18 Pacific
Reply: (edit)

Try stat or _stat. It gives you all the file details. If the file does not exist, it returns -1.


Report Offensive Follow Up For Removal

Response Number 3
Name: MindReader
Date: July 27, 2002 at 10:31:43 Pacific
Reply: (edit)

file *fp;
fp=fopen("filename","r");

now if fp==NULL

ur file does not exist..


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 7 Days.
Discuss in The Lounge
Poll History




Data Recovery Software