I only need a bool to check if file exists, while i'm giving the file location, depending on current directory.
I only need a bool to check if file exists, while i'm giving the file location, depending on current directory.
Last edited by ElastoManiac; 12-05-2005 at 07:04 AM.
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
try to open it. If open fails then the file doesn't exist. stat() will also indicate if the file exists.
you mean with <fstream>
i tryed that, and it doesn't work for reason unknown.
Code:ifstream fin; fin.open("sdfsdfsdf"); if(fin.fail) // doesn't work
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
Originally Posted by ElastoManiacthat is how I always checkCode:ifstream file; file.open("TehLeetFile"); if(!file.is_open()) cout<<"Tehleetness is busted!"; else cout<<"it work!!!!11!!!11!one!";
that worked, thanks.Originally Posted by Wraithan
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
You should be trying to call the fail() function, like this:if(fin.fail) // doesn't work
Code:if(fin.fail() )
I was using that all the time, just that i didn't wrote it 'cause i was tired!Originally Posted by 7stud
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
I use the win32 API call FindFirstFile and determine if the file is found by the returned WIN32_FIND_DATA; check out the first tutorial(s) here: http://www.adrianxw.dk/SoftwareSite/index.html
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
GetFileAttributes() doesn't require as much typingOriginally Posted by ahluka
Note that opening the file only indicates whether you can open the file. This may be due to it not existing, but it may also be due to you not having read access to it.
On a further note, NTFS has a weird feature called offline files that would cause serious delay if you touched a file this way. (On the other hand, that feature is practically never used.)
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
if you want to use win32 API you could use PathFileExists.
simple, but only works on drive letters (i.e. no unc paths)
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?