Victor said:
I can't really do anything about that.
I was kind of hoping you would tell me the rest of the sentance, as I
figured you might have accidentally deleted it whilst typing.
I have been doing some thinking...
//---------/ CODE START /----------//
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
const char dirString[] = "C:/";
const char fileString[] = "C:/test.txt";
int test1()
{
/*
Check to see if a file open for writing can
be read from.
*/
ofstream write(fileString, ios:

ut);
if (!write)
cout << "Could not open file to write!" << endl;
else
write << "Test\n";
ifstream read(fileString, ios::in);
if (!read)
{
cout << "Could not open file to read from!" << endl;
return 0;
}
if (read)
{
cout << "fstream can read from a file already"
<< " opened for writing!" << endl;
std::string line;
read.seekg(-4);
getline(read, line, '\n');
cout << line << "read from file" << endl;
return 1;
}
return 0;
}
int test2()
{
/*
Check to see if fstream can open a directory.
*/
fstream inDir(dirString);
if (inDir)
{
cout << "Directory opened with fstream\n" << endl;
cout << "Crap! There goes my theory...\n" << endl;
return 0;
}
else if (!inDir)
{
cout << "fstream cannot open directories!\n" << endl;
return 1;
}
return 0;
}
int main()
{
signed int test1Result = test1();
signed int test2Result = test2();
if (test1Result == 1 && test2Result == 1)
{
cout
<< "As we can't open a directory with fstream,\n"
<< "but can read from a file if it exists and\n"
<< "is open for writing, can we not use this\n"
<< "to be give a 100% correct answer as to\n"
<< "whether or not the given path is a file or\n"
<< "a directory?" << endl;
}
return 0;
}
//----------/ CODE END /-----------//
What's interesting is that you can't actually 'read' data from the file
when it's opened for writing, however, fstream appears to open the
file. To double-check I wrote a tiny proggy that opened the file in
advance, and kept it open until I pressed a key, and I still got the
same results from this program.
If I were to combine the two tests so that if the 'path name' exists
(which boost::filesystem::exists() will tell me. if the file can be
opened for reading, it's a file, of not, then it's a directory?
I hope this makes sense, and I would be happy to hear some feedback
from everyone. Please don't pick at the code quality. I am not an
expert and I am still learning things, so it may not be as secure as it
could be, but it was only designed for demonstration purposes.
Best wishes
Daz