bpp-core3  3.0.0
FileTools.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_IO_FILETOOLS_H
6 #define BPP_IO_FILETOOLS_H
7 
8 
9 // From the STL:
10 #include <string>
11 #include <vector>
12 #include <iostream>
13 #include <fstream>
14 #include <cstdio>
15 // #include <io.h> // required for directoryExists method
16 
17 namespace bpp
18 {
31 class FileTools
32 {
33 public:
34  static char DIR_SEP;
35 
36 public:
37  FileTools() {}
38  virtual ~FileTools() {}
39 
40 public:
47  static bool fileExists(const std::string& filename);
48 
57  static bool directoryExists(const std::string& path);
58 
73  static std::string getFileName(const std::string& path, char dirSep = DIR_SEP);
74 
82  static std::streampos getFileSize(const std::string& filename);
83 
91  static std::string getParent(const std::string& path, char dirSep = DIR_SEP);
92 
104  static std::string getExtension(const std::string& path);
105 
112  static std::vector<std::string> putStreamIntoVectorOfStrings(std::istream& input);
113 
119  static std::string getNextLine(std::istream& in);
120 };
121 } // end of namespace bpp.
122 #endif // BPP_IO_FILETOOLS_H
Some utilitary functions to deal with files.
Definition: FileTools.h:31
static std::streampos getFileSize(const std::string &filename)
Get the size of a file.
Definition: FileTools.cpp:59
static std::string getExtension(const std::string &path)
Get the extension of a file.
Definition: FileTools.cpp:86
static char DIR_SEP
Definition: FileTools.h:34
static std::vector< std::string > putStreamIntoVectorOfStrings(std::istream &input)
Reads a stream and write each line in a vector.
Definition: FileTools.cpp:94
static bool directoryExists(const std::string &path)
Tells if a directory exist.
Definition: FileTools.cpp:29
static std::string getNextLine(std::istream &in)
Get the next non-blanck line of a stream.
Definition: FileTools.cpp:108
static std::string getParent(const std::string &path, char dirSep=DIR_SEP)
Get the path of the parent directry of the given file/dir.
Definition: FileTools.cpp:71
static bool fileExists(const std::string &filename)
Tells if a file exist.
Definition: FileTools.cpp:19
static std::string getFileName(const std::string &path, char dirSep=DIR_SEP)
Get the name of of a file, without extension.
Definition: FileTools.cpp:39
virtual ~FileTools()
Definition: FileTools.h:38