#include <File.h>
#include <sys/stat.h>
#include <time.h>
namespace zpp
{
File::File(
const std::
string& aFileName):fileName(aFileName) {
}
File::~File() {
}
bool File::exist() {
struct _stat buf;
int result;
result = _stat(fileName.c_str(), &buf);
return (result == 0);
}
bool File::isDirectory() {
struct _stat buf;
if ( _stat(fileName.c_str(), &buf) != 0 ) {
//判断是否存在 return false;
}
return ( (buf.st_mode & S_IFDIR) !=0 );
}
long File::getFileSize() {
struct _stat buf;
int result;
result = _stat(fileName.c_str(), &buf);
if ( result == 0 ) {
return buf.st_size;
}
return 0;
}
char File::getFileDrive() {
struct _stat buf;
int result;
result = _stat(fileName.c_str(), &buf);
if ( result == 0 ) {
return ( buf.st_dev + 'A' );
}
return '0';
}
std::
string File::getCreateTime() {
struct _stat buf;
int result;
result = _stat(fileName.c_str(), &buf);
if ( result == 0 ) {
return std::
string( ctime(&buf.st_ctime) );
}
return "0";
}
std::
string File::getModifiedTime() {
struct _stat buf;
int result;
result = _stat(fileName.c_str(), &buf);
if ( result == 0 ) {
return std::
string( ctime(&buf.st_atime) );
}
return "0";
}
}