Computing.Net > Forums > Programming > C++ if exist

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ if exist

Reply to Message Icon

Name: djas
Date: February 3, 2005 at 15:09:53 Pacific
OS: Windows XP Pro SP2
CPU/Ram: P4 2.40 GHZ 256 RAM
Comment:

Is there a command in c++ that works like the "if exist" command in command prompt.
thanx

djas



Sponsored Link
Ads by Google

Response Number 1
Name: sen (by santanusen_82)
Date: February 6, 2005 at 21:19:42 Pacific
Reply:

Hello djas,
I think u wanna check a file for existence, right? You can use the 'open' system call to check for existence of a file. For that you need to use the O_CREAT flag along with O_EXCL flag. If the file already exists, the open call will fail and return -1. Let's check this sample code....

void main()
{

if( open("somefile.txt", O_CREAT + O_EXCL) == -1)
printf("File exists");

else
printf("File does not exist");
}

Santanu Sen
National Institute of Technology
Durgapur
India


0

Response Number 2
Name: djas
Date: February 10, 2005 at 05:20:49 Pacific
Reply:

Thanx that works great, sorry for not replying sooner, I had to reformat my hard drive.
thanx again

djas


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: C++ if exist

IF Exists with wildcards? www.computing.net/answers/programming/if-exists-with-wildcards/15334.html

Batch For DO(list of if exist set)? www.computing.net/answers/programming/batch-for-dolist-of-if-exist-set/16087.html

Loopinig batch file using IF EXIST www.computing.net/answers/programming/loopinig-batch-file-using-if-exist/17323.html