src
utilite
UFile.h
Go to the documentation of this file.
1
// Taken from UtiLite library r185 [www.utilite.googlecode.com]
2
3
/*
4
* utilite is a cross-platform library with
5
* useful utilities for fast and small developing.
6
* Copyright (C) 2010 Mathieu Labbe
7
*
8
* utilite is free library: you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
12
*
13
* utilite is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*/
21
22
#ifndef FILE_H
23
#define FILE_H
24
25
//#include "utilite/UtiLiteExp.h" // DLL export/import defines
26
27
#include "
utilite/UDirectory.h
"
28
#include <string>
29
35
class
UFile
36
{
37
public
:
43
static
bool
exists
(
const
std::string &filePath);
44
50
static
long
length
(
const
std::string &filePath);
51
57
static
int
erase
(
const
std::string &filePath);
58
65
static
int
rename
(
const
std::string &oldFilePath,
66
const
std::string &newFilePath);
67
73
static
std::string
getName
(
const
std::string & filePath);
74
75
static
std::string
getExtension
(
const
std::string &filePath);
76
77
public
:
82
UFile
(
const
std::string & path) :
path_
(path) {}
83
~UFile
() {}
84
89
bool
isValid
() {
return
exists
(
path_
);}
90
95
bool
exists
() {
return
exists
(
path_
);}
96
101
long
length
() {
return
length
(
path_
);}
102
107
int
rename
(
const
std::string &newName)
108
{
109
std::string ext = this->
getExtension
();
110
std::string newPath =
UDirectory::getDir
(
path_
) + std::string(
"/"
) + newName;
111
if
(ext.size())
112
{
113
newPath += std::string(
"."
) +
getExtension
(
path_
);
114
}
115
int
result =
rename
(
path_
, newPath);
116
if
(result == 0)
117
{
118
path_
= newPath;
119
}
120
return
result;
121
}
126
std::string
getName
() {
return
getName
(
path_
);}
131
std::string
getExtension
() {
return
getExtension
(
path_
);}
132
133
private
:
134
std::string
path_
;
135
};
136
137
#endif
UFile::rename
static int rename(const std::string &oldFilePath, const std::string &newFilePath)
Definition:
UFile.cpp:65
UFile::getName
std::string getName()
Definition:
UFile.h:126
UFile::erase
static int erase(const std::string &filePath)
Definition:
UFile.cpp:60
UFile
Definition:
UFile.h:35
UFile::length
long length()
Definition:
UFile.h:101
UDirectory.h
UFile::rename
int rename(const std::string &newName)
Definition:
UFile.h:107
UFile::UFile
UFile(const std::string &path)
Definition:
UFile.h:82
UDirectory::getDir
static std::string getDir(const std::string &filePath)
Definition:
UDirectory.cpp:262
UFile::~UFile
~UFile()
Definition:
UFile.h:83
UFile::getExtension
std::string getExtension()
Definition:
UFile.h:131
UFile::isValid
bool isValid()
Definition:
UFile.h:89
UFile::path_
std::string path_
Definition:
UFile.h:134
UFile::exists
bool exists()
Definition:
UFile.h:95
find_object_2d
Author(s): Mathieu Labbe
autogenerated on Mon Dec 12 2022 03:43:35