Reputation: 1873
I implemented a solution to the problem meant to be cross-platform and adherent to the C++ standard library.
bool isdir(const char *string) {
ofstream file(string, ios::out);
return file.fail();
}
Yet, if the file is actually writable, the program opens an empty file with string
name in its working directory.
How can I prevent this from happening?
Upvotes: 3
Views: 715
Reputation: 13451
There is no standard way of detecting if a file is a directory in C++. But you can use Boost.Filesystem. It is well portable.
Edit: It seems that this question has already been answered here.
Upvotes: 4