Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JFilesystem.hh
Go to the documentation of this file.
1#ifndef __JSYSTEM_JFILEJSYSTEM__
2#define __JSYSTEM_JFILEJSYSTEM__
3
4#include <string>
5#include <vector>
6#include <fstream>
7#include <dirent.h>
8
9
10namespace JSYSTEM {}
11namespace JPP { using namespace JSYSTEM; }
12
13namespace JSYSTEM {
14
15 /**
16 * Auxiliary data structure to list files in directory.
17 */
18 struct ls :
19 public std::vector<std::string>
20 {
21 /**
22 * Constructor.
23 *
24 * \param dir directory
25 */
26 ls(const std::string& dir)
27 {
28 DIR* top = opendir(dir.c_str());
29
30 if (top != NULL) {
31
32 for (dirent* i; (i = readdir(top)) != NULL; ) {
33 this->push_back(i->d_name);
34 }
35
36 closedir(top);
37 }
38 }
39 };
40
41
42 /**
43 * Rename file across file systems.
44 *
45 * \param inputFile input file
46 * \param outputFile input file
47 * \return zero upon success; else non-zero
48 */
49 inline int rename(const std::string& inputFile,
50 const std::string& outputFile)
51 {
52 using namespace std;
53
54 ifstream in (inputFile .c_str(), ios::binary);
55 ofstream out(outputFile.c_str(), ios::binary);
56
57 out << in.rdbuf();
58
59 if (out)
60 return remove(inputFile.c_str());
61 else
62 return -1;
63 }
64}
65
66#endif
string outputFile
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for operating system calls.
int rename(const std::string &inputFile, const std::string &outputFile)
Rename file across file systems.
Auxiliary data structure to list files in directory.
ls(const std::string &dir)
Constructor.