bpp-core3  3.0.0
FileTools.h
Go to the documentation of this file.
1 //
2 // File: FileTools.h
3 // Authors:
4 // Guillaume Deuchst
5 // Julien Dutheil
6 // Last modified: 2003-08-04 00:00:00
7 //
8 
9 /*
10  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
11 
12  This software is a computer program whose purpose is to provide utilitary
13  classes. This file belongs to the Bio++ Project.
14 
15  This software is governed by the CeCILL license under French law and
16  abiding by the rules of distribution of free software. You can use,
17  modify and/ or redistribute the software under the terms of the CeCILL
18  license as circulated by CEA, CNRS and INRIA at the following URL
19  "http://www.cecill.info".
20 
21  As a counterpart to the access to the source code and rights to copy,
22  modify and redistribute granted by the license, users are provided only
23  with a limited warranty and the software's author, the holder of the
24  economic rights, and the successive licensors have only limited
25  liability.
26 
27  In this respect, the user's attention is drawn to the risks associated
28  with loading, using, modifying and/or developing or reproducing the
29  software by the user in light of its specific status of free software,
30  that may mean that it is complicated to manipulate, and that also
31  therefore means that it is reserved for developers and experienced
32  professionals having in-depth computer knowledge. Users are therefore
33  encouraged to load and test the software's suitability as regards their
34  requirements in conditions enabling the security of their systems and/or
35  data to be ensured and, more generally, to use and operate it in the
36  same conditions as regards security.
37 
38  The fact that you are presently reading this means that you have had
39  knowledge of the CeCILL license and that you accept its terms.
40 */
41 
42 #ifndef BPP_IO_FILETOOLS_H
43 #define BPP_IO_FILETOOLS_H
44 
45 
46 
47 // From the STL:
48 #include <string>
49 #include <vector>
50 #include <iostream>
51 #include <fstream>
52 #include <cstdio>
53 // #include <io.h> // required for directoryExists method
54 
55 namespace bpp
56 {
69 class FileTools
70 {
71 public:
72  static char DIR_SEP;
73 
74 public:
75  FileTools() {}
76  virtual ~FileTools() {}
77 
78 public:
85  static bool fileExists(const std::string& filename);
86 
95  static bool directoryExists(const std::string& path);
96 
111  static std::string getFileName(const std::string& path, char dirSep = DIR_SEP);
112 
120  static std::streampos getFileSize(const std::string& filename);
121 
129  static std::string getParent(const std::string& path, char dirSep = DIR_SEP);
130 
142  static std::string getExtension(const std::string& path);
143 
150  static std::vector<std::string> putStreamIntoVectorOfStrings(std::istream& input);
151 
157  static std::string getNextLine(std::istream& in);
158 };
159 } // end of namespace bpp.
160 #endif // BPP_IO_FILETOOLS_H
Some utilitary functions to deal with files.
Definition: FileTools.h:70
static std::string getNextLine(std::istream &in)
Get the next non-blanck line of a stream.
Definition: FileTools.cpp:145
static char DIR_SEP
Definition: FileTools.h:72
static bool fileExists(const std::string &filename)
Tells if a file exist.
Definition: FileTools.cpp:56
static std::string getExtension(const std::string &path)
Get the extension of a file.
Definition: FileTools.cpp:123
static std::streampos getFileSize(const std::string &filename)
Get the size of a file.
Definition: FileTools.cpp:96
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:108
static bool directoryExists(const std::string &path)
Tells if a directory exist.
Definition: FileTools.cpp:66
static std::vector< std::string > putStreamIntoVectorOfStrings(std::istream &input)
Reads a stream and write each line in a vector.
Definition: FileTools.cpp:131
static std::string getFileName(const std::string &path, char dirSep=DIR_SEP)
Get the name of of a file, without extension.
Definition: FileTools.cpp:76
virtual ~FileTools()
Definition: FileTools.h:76