Essential Tools Module User's Guide : Chapter 10 File System Classes : RWFileStat
RWFileStat
RWFileStat is an abstraction of the state of a file system object and provides that information in a portable manner. Note that RWFileStat type is not assignable, copy constructible, or equality comparable:
// ...
RWFileStat s0 ("somefile.txt");
RWFileStat s1;
s1 = s0; // fail; not Assignable
RWFileStat s2 (s0); // fail; not Copy Constructible
return s0 == s1; // fail; not Comparable
// ....
Construction
Construct an RWFileStat object by passing the name of a valid file:
 
RWFileStat st ("filename");
 
For links, the RWFileStat object will stat the link object itself and not the target of the symbolic link. If you want to stat the target use:
 
RWFileStat st ("filename", true);
Example
A function which prints the type of the file system object stat'ed:
 
void list_type (const char* filename)
{
try {
RWFileStat st (filename);
// print type
if (st.isSymlink ())
std::cout << " symlink";
if (st.isFile ())
std::cout << " file";
if (st.isBlock ())
std::cout << " block";
if (st.isDirectory ())
std::cout << " directory";
if (st.isCharacter ())
std::cout << " character";
if (st.isFifo ())
std::cout << " FIFO";
// List the file mode
std::cout << " 0x"
<< std::hex << std::setw (8) << std::setfill('0')
<< st.mode () << std::endl;
}
catch (const RWInternalErr& e) {
std::cerr << " Exception : " << e.why ();
}
catch (...) {
std::cerr << " Unknown exception.";
}
}