reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofFileUtils.h
Go to the documentation of this file.
1#pragma once
2
3// FIXME: constants deprecated only
4#include "ofConstants.h"
5#include <fstream>
6
7//----------------------------------------------------------
8// ofBuffer
9//----------------------------------------------------------
10
16
17public:
18 ofBuffer();
19
26 ofBuffer(const char * buffer, std::size_t size);
27
31 ofBuffer(std::istream & stream, std::size_t ioBlockSize = 1024);
32
39 void set(const char * buffer, std::size_t size);
40
44 void set(const std::string & text);
45
50 bool set(std::istream & stream, std::size_t ioBlockSize = 1024);
51
55 void setall(char mem);
56
60 void append(const std::string& buffer);
61
68 void append(const char * buffer, std::size_t size);
69
74 void reserve(std::size_t size);
75
77 bool writeTo(std::ostream & stream) const;
78
80 void clear();
81
86 void allocate(std::size_t size);
87
95 void resize(std::size_t size);
96
101 char * getData();
102
107 const char * getData() const;
108 OF_DEPRECATED_MSG("Use getData instead",char * getBinaryBuffer());
109 OF_DEPRECATED_MSG("Use getData instead",const char * getBinaryBuffer() const);
110
114 std::string getText() const;
115
119 operator std::string() const;
120
122 ofBuffer & operator=(const std::string & text);
123
127 std::size_t size() const;
128
129 OF_DEPRECATED_MSG("use a lines iterator instead",std::string getNextLine());
130 OF_DEPRECATED_MSG("use a lines iterator instead",std::string getFirstLine());
131 OF_DEPRECATED_MSG("use a lines iterator instead",bool isLastLine());
132 OF_DEPRECATED_MSG("use a lines iterator instead",void resetLineReader());
133
134 friend std::ostream & operator<<(std::ostream & ostr, const ofBuffer & buf);
135 friend std::istream & operator>>(std::istream & istr, ofBuffer & buf);
136
137 std::vector<char>::iterator begin();
138 std::vector<char>::iterator end();
139 std::vector<char>::const_iterator begin() const;
140 std::vector<char>::const_iterator end() const;
141 std::vector<char>::reverse_iterator rbegin();
142 std::vector<char>::reverse_iterator rend();
143 std::vector<char>::const_reverse_iterator rbegin() const;
144 std::vector<char>::const_reverse_iterator rend() const;
145
148
149 struct Line {
150 Line(std::vector<char>::iterator _begin, std::vector<char>::iterator _end);
151 const std::string & operator*() const;
152 const std::string * operator->() const;
153 const std::string & asString() const;
154
155 using value_type = std::string;
156 using iterator_category = std::forward_iterator_tag;
157 using difference_type = std::ptrdiff_t;
158 using pointer = const value_type*;
159 using reference = const value_type&;
160
162 Line& operator++();
163
165 Line operator++(int);
166
167 bool operator!=(Line const& rhs) const;
168 bool operator==(Line const& rhs) const;
169
171 bool empty() const;
172
173 private:
174 std::string line;
175 std::vector<char>::iterator _current, _begin, _end;
176 };
177
180 struct RLine {
181 RLine(std::vector<char>::reverse_iterator _begin, std::vector<char>::reverse_iterator _end);
182 const std::string & operator*() const;
183 const std::string * operator->() const;
184 const std::string & asString() const;
185
186 using value_type = std::string;
187 using iterator_category = std::forward_iterator_tag;
188 using difference_type = std::ptrdiff_t;
189 using pointer = const value_type*;
190 using reference = const value_type&;
191
193 RLine& operator++();
194
196 RLine operator++(int);
197
198 bool operator!=(RLine const& rhs) const;
199 bool operator==(RLine const& rhs) const;
200
202 bool empty() const;
203
204 private:
205 std::string line;
206 std::vector<char>::reverse_iterator _current, _rbegin, _rend;
207 };
208
211 struct Lines{
212 Lines(std::vector<char>::iterator begin, std::vector<char>::iterator end);
213
215 Line begin();
216
218 Line end();
219
222
223 private:
224 std::vector<char>::iterator _begin, _end;
225 };
226
227
230 struct RLines{
231 RLines(std::vector<char>::reverse_iterator rbegin, std::vector<char>::reverse_iterator rend);
232
234 RLine begin();
235
237 RLine end();
238
239 private:
240 std::vector<char>::reverse_iterator _rbegin, _rend;
241 };
242
249 Lines getLines();
250
259
260private:
261 std::vector<char> buffer;
262 Line currentLine;
263};
264
265//--------------------------------------------------
273ofBuffer ofBufferFromFile(const of::filesystem::path & path, bool binary=true);
274
275//--------------------------------------------------
284bool ofBufferToFile(const of::filesystem::path & path, const ofBuffer& buffer, bool binary=true);
285
286//--------------------------------------------------
292public:
293
298 static std::string getFileExt(const of::filesystem::path& filename);
299
304// MARK: - near future
305// static of::filesystem::path removeExt(const of::filesystem::path& filename);
306 static std::string removeExt(const of::filesystem::path& filename);
307
312 static std::string addLeadingSlash(const of::filesystem::path& path);
313
318// MARK: - near future
319// static of::filesystem::path addTrailingSlash(const of::filesystem::path& path);
320 static std::string addTrailingSlash(const of::filesystem::path& path);
321
327 static std::string removeTrailingSlash(const of::filesystem::path& path);
328
336 static std::string getPathForDirectory(const of::filesystem::path& path);
337
346 // MARK - near future
347 // static of::filesystem::path getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData = true);
348 static std::string getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData = true);
349
356 static bool isAbsolute(const of::filesystem::path& path);
357
368 // FIXME: Deprecate / Remove this.
369 static std::string getFileName(const of::filesystem::path& filePath, bool bRelativeToData = true);
370
377 static std::string getBaseName(const of::filesystem::path& filePath);
378
388// MARK: - near future
389// static of::filesystem::path getEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData = true);
390 static std::string getEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData = true);
391
404 static bool createEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData = true, bool bRecursive = true);
405
414 static std::string getCurrentWorkingDirectory();
415
422// MARK: - near future
423// static of::filesystem::path join(const of::filesystem::path& path1, const of::filesystem::path& path2);
424 static std::string join(const of::filesystem::path& path1, const of::filesystem::path& path2);
425
433 static std::string getCurrentExePath();
434
441// MARK: - near future
442// static of::filesystem::path getCurrentExeDir();
443 static std::string getCurrentExeDir();
444
452 static std::string getUserHomeDir();
453
461 // MARK: - near future
462// static of::filesystem::path makeRelative(const of::filesystem::path & from, const of::filesystem::path & to);
463 static std::string makeRelative(const of::filesystem::path & from, const of::filesystem::path & to);
464};
465
472class ofFile: public std::fstream{
473
474public:
475
477 enum Mode{
479 ReadOnly, //< read only from the file, do not write
480 WriteOnly, //< write only to the file, do not read
481 ReadWrite, //< read from and write to the file
482 Append //< append data to the end of the file, do not overwrite
483 };
484
489 ofFile();
490
501 ofFile(const of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true);
502
507 ofFile(const ofFile & mom);
508
512 ofFile & operator= (const ofFile & mom);
513
514 ~ofFile();
515
526// bool open(of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true);
527 bool open(const of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true);
528
539 bool openFromCWD(const of::filesystem::path & path, Mode mode=ReadOnly, bool binary=true);
540
548 bool changeMode(Mode mode, bool binary=true);
549
551 void close();
552
558 bool create();
559
566 bool create(const of::filesystem::path & path);
567
571 bool exists() const;
572
576// MARK: - near future
577// of::filesystem::path path() const;
578 std::string path() const;
579
584 std::string getExtension() const;
585
590 std::string getFileName() const;
591
597 std::string getBaseName() const;
598
604// MARK: - near future
605// of::filesystem::path getEnclosingDirectory() const;
606 std::string getEnclosingDirectory() const;
607
612// MARK: - near future
613// of::filesystem::path getAbsolutePath() const;
614 std::string getAbsolutePath() const;
615
619 bool canRead() const;
620
624 bool canWrite() const;
625
629 bool canExecute() const;
630
634 bool isFile() const;
635
640 bool isLink() const;
641
645 bool isDirectory() const;
646
653 bool isDevice() const;
654
661 bool isHidden() const;
662
664 void setWriteable(bool writeable=true);
665
666 OF_DEPRECATED_MSG("Use ofFile::setWriteable(!flag).", void setReadOnly(bool flag));
667
669 void setReadable(bool readable=true);
670
672 void setExecutable(bool executable=true);
673
686 bool copyTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false) const;
687
700 bool moveTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false);
701
714 bool renameTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false);
715
724 bool remove(bool recursive=false);
725
729 uint64_t getSize() const;
730
731 // this allows to compare files by their paths, also provides sorting
732 // and use as key in stl containers
733 bool operator==(const ofFile & file) const;
734 bool operator!=(const ofFile & file) const;
735 bool operator<(const ofFile & file) const;
736 bool operator<=(const ofFile & file) const;
737 bool operator>(const ofFile & file) const;
738 bool operator>=(const ofFile & file) const;
739
740 //------------------
741 // stream operations
742 //------------------
743
744 // since this class inherits from fstream it can be used as a r/w stream:
745 // http://www.cplusplus.com/reference/iostream/fstream/
746
751
756 bool writeFromBuffer(const ofBuffer & buffer);
757
766 std::filebuf * getFileBuffer() const;
767
768 operator of::filesystem::path(){
769 return myFile;
770 }
771//
772 operator of::filesystem::path() const{
773 return myFile;
774 }
775
776 //-------
777 //static helpers
778 //-------
779
792 static bool copyFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData = true, bool overwrite = false);
793
808 static bool moveFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData = true, bool overwrite = false);
809
817 static bool doesFileExist(const of::filesystem::path& fPath, bool bRelativeToData = true);
818
825 static bool removeFile(const of::filesystem::path& path, bool bRelativeToData = true);
826
827private:
828 bool isWriteMode();
829 bool openStream(Mode _mode, bool binary);
830 void copyFrom(const ofFile & mom);
831
832 of::filesystem::path myFile;
833 Mode mode;
834 bool binary;
835};
836
843
844public:
845
850 ofDirectory();
851
855 ofDirectory(const of::filesystem::path & path);
856
860 void open(const of::filesystem::path & path);
861
865 void openFromCWD(const of::filesystem::path & path);
866
868 void close();
869
874 bool create(bool recursive = false);
875
879 bool exists() const;
880
884// MARK: - near future
885// of::filesystem::path path() const;
886 std::string path() const;
887
892// MARK: - near future
893// of::filesystem::path getAbsolutePath() const;
894 std::string getAbsolutePath() const;
895
899 bool canRead() const;
900
904 bool canWrite() const;
905
909 bool canExecute() const;
910
914 bool isDirectory() const;
915
922 bool isHidden() const;
923
927 void setWriteable(bool writeable=true);
928
929 OF_DEPRECATED_MSG("Use ofDirectory::setWriteable(!flag).", void setReadOnly(bool flag));
930
934 void setReadable(bool readable=true);
935
939 void setExecutable(bool executable=true);
940
947 void setShowHidden(bool showHidden);
948
961 bool copyTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false);
962
975 bool moveTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false);
976
989 bool renameTo(const of::filesystem::path& path, bool bRelativeToData = true, bool overwrite = false);
990
999 bool remove(bool recursive);
1000
1001 //-------------------
1002 // dirList operations
1003 //-------------------
1004
1012 void allowExt(const std::string& extension);
1013
1021 std::size_t listDir(const of::filesystem::path & path);
1022
1029 std::size_t listDir();
1030
1032 std::string getOriginalDirectory() const;
1033
1043 std::string getName(std::size_t position) const;
1044
1054 std::string getPath(std::size_t position) const;
1055
1071 ofFile getFile(std::size_t position, ofFile::Mode mode=ofFile::Reference, bool binary=true) const;
1072
1078 const std::vector<ofFile> & getFiles() const;
1079
1088 ofFile operator[](std::size_t position) const;
1089
1097 bool getShowHidden() const;
1098
1102 void reset();
1103
1109
1115 void sort(const SortMode & mode = SORT_NATURAL);
1116
1121 void sortByDate();
1122
1127
1133 std::size_t size() const;
1134
1135 OF_DEPRECATED_MSG("Use size() instead.", int numFiles());
1136
1137 // this allows to compare directories by their paths, also provides sorting
1138 // and use as key in stl containers
1139 bool operator==(const ofDirectory & dir) const;
1140 bool operator!=(const ofDirectory & dir) const;
1141 bool operator<(const ofDirectory & dir) const;
1142 bool operator<=(const ofDirectory & dir) const;
1143 bool operator>(const ofDirectory & dir) const;
1144 bool operator>=(const ofDirectory & dir) const;
1145
1146 operator of::filesystem::path(){
1147 return myDir;
1148 }
1149
1150 operator of::filesystem::path() const{
1151 return myDir;
1152 }
1153
1154 //-------
1155 // static helpers
1156 //-------
1157
1168 static bool createDirectory(const of::filesystem::path& dirPath, bool bRelativeToData = true, bool recursive = false);
1169
1179 static bool isDirectoryEmpty(const of::filesystem::path& dirPath, bool bRelativeToData = true );
1180
1189 static bool doesDirectoryExist(const of::filesystem::path& dirPath, bool bRelativeToData = true);
1190
1191
1199 static bool removeDirectory(const of::filesystem::path& path, bool deleteIfNotEmpty, bool bRelativeToData = true);
1200
1201 std::vector<ofFile>::const_iterator begin() const;
1202 std::vector<ofFile>::const_iterator end() const;
1203 std::vector<ofFile>::const_reverse_iterator rbegin() const;
1204 std::vector<ofFile>::const_reverse_iterator rend() const;
1205
1206 of::filesystem::path myDir;
1208 std::vector <std::string> extensions;
1209 std::vector <ofFile> files;
1211
1212};
1213
1219void ofEnableDataPath();
1220
1225void ofDisableDataPath();
1226
1238// MARK: - near future
1239//of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool absolute=false);
1240std::string ofToDataPath(const of::filesystem::path & path, bool absolute=false);
1241
1250
1259void ofSetDataPathRoot(const of::filesystem::path& root);
1260
1262namespace of{
1263namespace priv{
1264 void initfileutils();
1265}
1266}
Definition ofFileUtils.h:15
void setall(char mem)
Definition ofFileUtils.cpp:111
OF_DEPRECATED_MSG("use a lines iterator instead", std::string getNextLine())
OF_DEPRECATED_MSG("use a lines iterator instead", std::string getFirstLine())
bool set(std::istream &stream, std::size_t ioBlockSize=1024)
std::vector< char >::iterator begin()
Definition ofFileUtils.cpp:236
void allocate(std::size_t size)
Definition ofFileUtils.cpp:155
void append(const std::string &buffer)
Definition ofFileUtils.cpp:135
bool writeTo(std::ostream &stream) const
Write contents of the buffer to an output stream.
Definition ofFileUtils.cpp:116
ofBuffer()
Definition ofFileUtils.cpp:77
std::vector< char >::iterator end()
Definition ofFileUtils.cpp:241
void set(const char *buffer, std::size_t size)
Definition ofFileUtils.cpp:125
friend std::ostream & operator<<(std::ostream &ostr, const ofBuffer &buf)
std::size_t size() const
Definition ofFileUtils.cpp:205
void clear()
Remove all bytes from the buffer, leaving a size of 0.
Definition ofFileUtils.cpp:150
ofBuffer(std::istream &stream, std::size_t ioBlockSize=1024)
friend std::istream & operator>>(std::istream &istr, ofBuffer &buf)
std::string getText() const
Definition ofFileUtils.cpp:186
ofBuffer & operator=(const std::string &text)
set contents of the buffer from a string
Definition ofFileUtils.cpp:199
OF_DEPRECATED_MSG("Use getData instead", const char *getBinaryBuffer() const)
OF_DEPRECATED_MSG("use a lines iterator instead", void resetLineReader())
OF_DEPRECATED_MSG("use a lines iterator instead", bool isLastLine())
std::vector< char >::reverse_iterator rbegin()
Definition ofFileUtils.cpp:256
void reserve(std::size_t size)
Definition ofFileUtils.cpp:145
RLines getReverseLines()
Definition ofFileUtils.cpp:437
void resize(std::size_t size)
Definition ofFileUtils.cpp:160
char * getData()
Definition ofFileUtils.cpp:166
OF_DEPRECATED_MSG("Use getData instead", char *getBinaryBuffer())
std::vector< char >::reverse_iterator rend()
Definition ofFileUtils.cpp:261
Lines getLines()
Definition ofFileUtils.cpp:432
Definition ofFileUtils.h:842
void sort(const SortMode &mode=SORT_NATURAL)
Definition ofFileUtils.cpp:1524
static bool isDirectoryEmpty(const of::filesystem::path &dirPath, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1655
bool canExecute() const
Definition ofFileUtils.cpp:1247
ofFile getFile(std::size_t position, ofFile::Mode mode=ofFile::Reference, bool binary=true) const
Definition ofFileUtils.cpp:1451
bool isHidden() const
Definition ofFileUtils.cpp:1252
bool copyTo(const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
Definition ofFileUtils.cpp:1288
std::string path() const
Definition ofFileUtils.cpp:1215
const std::vector< ofFile > & getFiles() const
Definition ofFileUtils.cpp:1462
std::vector< std::string > extensions
Definition ofFileUtils.h:1208
void setWriteable(bool writeable=true)
Definition ofFileUtils.cpp:1257
void setExecutable(bool executable=true)
Definition ofFileUtils.cpp:1273
std::string originalDirectory
Definition ofFileUtils.h:1207
OF_DEPRECATED_MSG("Use ofDirectory::setWriteable(!flag).", void setReadOnly(bool flag))
ofDirectory getSorted()
Definition ofFileUtils.cpp:1570
ofFile operator[](std::size_t position) const
Definition ofFileUtils.cpp:1457
void open(const of::filesystem::path &path)
Definition ofFileUtils.cpp:1168
of::filesystem::path myDir
Definition ofFileUtils.h:1206
std::string getAbsolutePath() const
Definition ofFileUtils.cpp:1228
std::vector< ofFile >::const_iterator begin() const
Definition ofFileUtils.cpp:1698
void setReadable(bool readable=true)
Definition ofFileUtils.cpp:1268
void reset()
Definition ofFileUtils.cpp:1475
bool operator<(const ofDirectory &dir) const
Definition ofFileUtils.cpp:1678
std::string getOriginalDirectory() const
Definition ofFileUtils.cpp:1436
static bool createDirectory(const of::filesystem::path &dirPath, bool bRelativeToData=true, bool recursive=false)
Definition ofFileUtils.cpp:1606
bool operator<=(const ofDirectory &dir) const
Definition ofFileUtils.cpp:1683
ofDirectory()
Definition ofFileUtils.cpp:1157
bool operator==(const ofDirectory &dir) const
Definition ofFileUtils.cpp:1668
std::size_t size() const
Definition ofFileUtils.cpp:1578
static bool doesDirectoryExist(const of::filesystem::path &dirPath, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1640
bool remove(bool recursive)
Definition ofFileUtils.cpp:1357
std::vector< ofFile >::const_iterator end() const
Definition ofFileUtils.cpp:1703
static bool removeDirectory(const of::filesystem::path &path, bool deleteIfNotEmpty, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1592
std::size_t listDir()
Definition ofFileUtils.cpp:1391
bool renameTo(const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
Definition ofFileUtils.cpp:1352
bool operator>=(const ofDirectory &dir) const
Definition ofFileUtils.cpp:1693
void close()
Close the currently open path.
Definition ofFileUtils.cpp:1182
void setShowHidden(bool showHidden)
Definition ofFileUtils.cpp:1278
bool canWrite() const
Definition ofFileUtils.cpp:1242
bool moveTo(const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
Definition ofFileUtils.cpp:1343
std::string getPath(std::size_t position) const
Definition ofFileUtils.cpp:1446
OF_DEPRECATED_MSG("Use size() instead.", int numFiles())
SortMode
Definition ofFileUtils.h:1104
@ SORT_BY_DATE
Definition ofFileUtils.h:1107
@ SORT_FAST
Definition ofFileUtils.h:1105
@ SORT_NATURAL
Definition ofFileUtils.h:1106
bool canRead() const
Definition ofFileUtils.cpp:1237
bool isDirectory() const
Definition ofFileUtils.cpp:1283
std::string getName(std::size_t position) const
Definition ofFileUtils.cpp:1441
std::vector< ofFile > files
Definition ofFileUtils.h:1209
void allowExt(const std::string &extension)
Definition ofFileUtils.cpp:1377
bool operator!=(const ofDirectory &dir) const
Definition ofFileUtils.cpp:1673
bool operator>(const ofDirectory &dir) const
Definition ofFileUtils.cpp:1688
bool create(bool recursive=false)
Definition ofFileUtils.cpp:1187
bool exists() const
Definition ofFileUtils.cpp:1207
std::vector< ofFile >::const_reverse_iterator rend() const
Definition ofFileUtils.cpp:1713
std::vector< ofFile >::const_reverse_iterator rbegin() const
Definition ofFileUtils.cpp:1708
void openFromCWD(const of::filesystem::path &path)
Definition ofFileUtils.cpp:1175
bool getShowHidden() const
Definition ofFileUtils.cpp:1470
void sortByDate()
Definition ofFileUtils.cpp:1516
bool showHidden
Definition ofFileUtils.h:1210
Definition ofFileUtils.h:472
bool writeFromBuffer(const ofBuffer &buffer)
Definition ofFileUtils.cpp:627
void setReadable(bool readable=true)
Set the readable flag of the current path.
Definition ofFileUtils.cpp:856
bool canWrite() const
Definition ofFileUtils.cpp:728
bool remove(bool recursive=false)
Definition ofFileUtils.cpp:1034
bool operator<=(const ofFile &file) const
Definition ofFileUtils.cpp:1087
bool open(const of::filesystem::path &path, Mode mode=ReadOnly, bool binary=true)
Definition ofFileUtils.cpp:559
std::string getBaseName() const
Definition ofFileUtils.cpp:675
bool isLink() const
Definition ofFileUtils.cpp:793
std::string getFileName() const
Definition ofFileUtils.cpp:670
static bool removeFile(const of::filesystem::path &path, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1139
bool copyTo(const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false) const
Definition ofFileUtils.cpp:914
bool moveTo(const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
Definition ofFileUtils.cpp:971
bool operator<(const ofFile &file) const
Definition ofFileUtils.cpp:1082
~ofFile()
Definition ofFileUtils.cpp:484
std::string getExtension() const
Definition ofFileUtils.cpp:659
void setWriteable(bool writeable=true)
Set the writable flag of the current path.
Definition ofFileUtils.cpp:825
bool operator==(const ofFile &file) const
Definition ofFileUtils.cpp:1072
bool operator!=(const ofFile &file) const
Definition ofFileUtils.cpp:1077
bool exists() const
Definition ofFileUtils.cpp:643
ofFile()
Definition ofFileUtils.cpp:472
uint64_t getSize() const
Definition ofFileUtils.cpp:1062
bool operator>=(const ofFile &file) const
Definition ofFileUtils.cpp:1097
std::string getAbsolutePath() const
Definition ofFileUtils.cpp:689
ofBuffer readToBuffer()
Definition ofFileUtils.cpp:618
bool isDevice() const
Definition ofFileUtils.cpp:803
bool create()
Definition ofFileUtils.cpp:597
std::filebuf * getFileBuffer() const
Definition ofFileUtils.cpp:638
void setExecutable(bool executable=true)
Set the executable flag of the current path.
Definition ofFileUtils.cpp:881
static bool doesFileExist(const of::filesystem::path &fPath, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1128
OF_DEPRECATED_MSG("Use ofFile::setWriteable(!flag).", void setReadOnly(bool flag))
bool openFromCWD(const of::filesystem::path &path, Mode mode=ReadOnly, bool binary=true)
Definition ofFileUtils.cpp:566
bool isFile() const
Definition ofFileUtils.cpp:788
std::string getEnclosingDirectory() const
Definition ofFileUtils.cpp:682
bool canRead() const
Definition ofFileUtils.cpp:694
bool isDirectory() const
Definition ofFileUtils.cpp:798
bool renameTo(const of::filesystem::path &path, bool bRelativeToData=true, bool overwrite=false)
Definition ofFileUtils.cpp:1029
static bool copyFromTo(const of::filesystem::path &pathSrc, const of::filesystem::path &pathDst, bool bRelativeToData=true, bool overwrite=false)
Definition ofFileUtils.cpp:1105
static bool moveFromTo(const of::filesystem::path &pathSrc, const of::filesystem::path &pathDst, bool bRelativeToData=true, bool overwrite=false)
Definition ofFileUtils.cpp:1117
bool operator>(const ofFile &file) const
Definition ofFileUtils.cpp:1092
bool changeMode(Mode mode, bool binary=true)
Definition ofFileUtils.cpp:573
bool isHidden() const
Definition ofFileUtils.cpp:816
ofFile & operator=(const ofFile &mom)
Definition ofFileUtils.cpp:498
void close()
Close a currently open file.
Definition ofFileUtils.cpp:591
std::string path() const
Definition ofFileUtils.cpp:654
bool canExecute() const
Definition ofFileUtils.cpp:761
Mode
file access mode
Definition ofFileUtils.h:477
@ Append
Definition ofFileUtils.h:482
@ ReadWrite
Definition ofFileUtils.h:481
@ Reference
Definition ofFileUtils.h:478
@ ReadOnly
Definition ofFileUtils.h:479
@ WriteOnly
Definition ofFileUtils.h:480
Definition ofFileUtils.h:291
static std::string removeExt(const of::filesystem::path &filename)
Definition ofFileUtils.cpp:1769
static std::string getCurrentExeDir()
Definition ofFileUtils.cpp:1915
static std::string removeTrailingSlash(const of::filesystem::path &path)
Definition ofFileUtils.cpp:1799
static std::string getUserHomeDir()
Definition ofFileUtils.cpp:1920
static std::string getEnclosingDirectory(const of::filesystem::path &filePath, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1830
static std::string getAbsolutePath(const of::filesystem::path &path, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1846
static std::string getPathForDirectory(const of::filesystem::path &path)
Definition ofFileUtils.cpp:1776
static std::string getBaseName(const of::filesystem::path &filePath)
Definition ofFileUtils.cpp:1822
static bool createEnclosingDirectory(const of::filesystem::path &filePath, bool bRelativeToData=true, bool bRecursive=true)
Definition ofFileUtils.cpp:1839
static std::string addTrailingSlash(const of::filesystem::path &path)
Definition ofFileUtils.cpp:1740
static std::string makeRelative(const of::filesystem::path &from, const of::filesystem::path &to)
Definition ofFileUtils.cpp:1936
static std::string addLeadingSlash(const of::filesystem::path &path)
Definition ofFileUtils.cpp:1726
static std::string getCurrentExePath()
Definition ofFileUtils.cpp:1882
static std::string getFileExt(const of::filesystem::path &filename)
Definition ofFileUtils.cpp:1761
static bool isAbsolute(const of::filesystem::path &path)
Definition ofFileUtils.cpp:1861
static std::string getFileName(const of::filesystem::path &filePath, bool bRelativeToData=true)
Definition ofFileUtils.cpp:1810
static std::string getCurrentWorkingDirectory()
Definition ofFileUtils.cpp:1866
static std::string join(const of::filesystem::path &path1, const of::filesystem::path &path2)
Definition ofFileUtils.cpp:1876
void initfileutils()
Definition ofFileUtils.cpp:63
Definition ofEvents.cpp:625
bool ofBufferToFile(const of::filesystem::path &path, const ofBuffer &buffer, bool binary=true)
Definition ofFileUtils.cpp:460
void ofEnableDataPath()
Enable the use of the data path.
Definition ofFileUtils.cpp:1961
void ofSetDataPathRoot(const of::filesystem::path &root)
Set the relative path to the data/ folder from the executable.
Definition ofFileUtils.cpp:1981
ofBuffer ofBufferFromFile(const of::filesystem::path &path, bool binary=true)
Definition ofFileUtils.cpp:454
bool ofRestoreWorkingDirectoryToDefault()
Reset the working directory to the platform default.
Definition ofFileUtils.cpp:1971
void ofDisableDataPath()
Disable the use of the data path.
Definition ofFileUtils.cpp:1966
std::string ofToDataPath(const of::filesystem::path &path, bool absolute=false)
Make a path relative to the location of the data/ folder.
Definition ofFileUtils.cpp:1988
Definition ofFileUtils.h:149
const std::string * operator->() const
Definition ofFileUtils.cpp:303
std::string value_type
Definition ofFileUtils.h:155
std::ptrdiff_t difference_type
Definition ofFileUtils.h:157
bool operator!=(Line const &rhs) const
Definition ofFileUtils.cpp:326
Line & operator++()
Increment to the next line.
Definition ofFileUtils.cpp:313
bool operator==(Line const &rhs) const
Definition ofFileUtils.cpp:331
const std::string & asString() const
Definition ofFileUtils.cpp:308
std::forward_iterator_tag iterator_category
Definition ofFileUtils.h:156
const std::string & operator*() const
Definition ofFileUtils.cpp:298
const value_type * pointer
Definition ofFileUtils.h:158
bool empty() const
Is this line empty? (aka an empty string "")
Definition ofFileUtils.cpp:335
const value_type & reference
Definition ofFileUtils.h:159
Definition ofFileUtils.h:211
Line end()
Get the last line in the buffer.
Definition ofFileUtils.cpp:411
Line begin()
Get the first line in the buffer.
Definition ofFileUtils.cpp:406
Definition ofFileUtils.h:180
const value_type & reference
Definition ofFileUtils.h:190
const std::string & operator*() const
Definition ofFileUtils.cpp:359
bool operator==(RLine const &rhs) const
Definition ofFileUtils.cpp:392
const std::string * operator->() const
Definition ofFileUtils.cpp:364
RLine & operator++()
Increment to the next line.
Definition ofFileUtils.cpp:374
const std::string & asString() const
Definition ofFileUtils.cpp:369
std::forward_iterator_tag iterator_category
Definition ofFileUtils.h:187
bool operator!=(RLine const &rhs) const
Definition ofFileUtils.cpp:387
bool empty() const
Is this line empty? (aka an empty string "")
Definition ofFileUtils.cpp:396
std::string value_type
Definition ofFileUtils.h:186
const value_type * pointer
Definition ofFileUtils.h:189
std::ptrdiff_t difference_type
Definition ofFileUtils.h:188
Definition ofFileUtils.h:230
RLine end()
Get the last line in the buffer.
Definition ofFileUtils.cpp:427
RLine begin()
Get the first line in the buffer.
Definition ofFileUtils.cpp:422