File.cpp 876 Bytes
Newer Older
1
#include "File.h"
2
#include "Utils.h"
3

4
5
6
#include <stdexcept>
#include <sys/stat.h>

7
8
9
10
11
12
13
namespace fs
{

File::File( const std::string& path, const std::string& fileName )
    : m_path( path )
    , m_name( fileName )
    , m_fullPath( path + ( *path.rbegin() != '/' ? "/" : "" ) + fileName )
14
    , m_extension( utils::file::extension( fileName ) )
15
{
16
17
18
19
    struct stat s;
    if ( lstat( m_fullPath.c_str(), &s ) )
        throw std::runtime_error( "Failed to get file stats" );
    m_lastModificationDate = s.st_mtim.tv_sec;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
}

const std::string& File::name() const
{
    return m_name;
}

const std::string& File::path() const
{
    return m_path;
}

const std::string& File::fullPath() const
{
    return m_fullPath;
}

const std::string& File::extension() const
{
    return m_extension;
}

42
43
44
45
46
unsigned int File::lastModificationDate() const
{
    return m_lastModificationDate;
}

47
}