SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Dir.h
Go to the documentation of this file.
1 
2 /*
3  For more information, please see: http://software.sci.utah.edu
4 
5  The MIT License
6 
7  Copyright (c) 2009 Scientific Computing and Imaging Institute,
8  University of Utah.
9 
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included
19  in all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 */
29 
30 #ifndef CORE_UTIL_DIR_H
31 #define CORE_UTIL_DIR_H
32 
33 
34 #include <string>
35 #include <vector>
36 
37 
38 #ifdef _WIN32
39 #include <io.h>
40 #include <direct.h>
41 #include <sys/stat.h>
42 #define S_IRUSR 0x0100
43 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
44 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
45 #endif
46 
48 namespace SCIRun {
49 
50  /**************************************
51 
52  @class
53  Dir
54 
55  Short Description...
56 
57  GENERAL INFORMATION
58 
59  Dir.h
60  @author
61  Steven G. Parker
62  Department of Computer Science
63  University of Utah
64 
65  KEYWORDS
66  Dir
67 
68  DESCRIPTION
69  Long description...
70 
71  WARNING
72 
73  ****************************************/
74 
75  class SCISHARE Dir {
76  public:
77  Dir();
78  Dir(const Dir&);
79  Dir(const std::string&);
80  ~Dir();
81  Dir& operator=(const Dir&);
82 
83  static Dir create(const std::string& name);
84  static Dir current_directory();
85 
86  void remove(bool throwOnError = true);
87 
88  // removes even if the directory has contents
89  void forceRemove(bool throwOnError = true);
90 
91  // remove a file
92  void remove(const std::string& filename, bool throwOnError = true);
93 
94  // copy this directory to under the destination directory
95  void copy(Dir& destDir);
96  void move(Dir& destDir);
97 
98  // copy a file in this directory to the destination directory
99  void copy(const std::string& filename, Dir& destDir);
100  void move(const std::string& filename, Dir& destDir);
101 
102  Dir createSubdir(const std::string& name);
103  Dir getSubdir(const std::string& name);
104  bool exists();
105  bool isfile();
106 
107  void getFilenamesBySuffix(const std::string& suffix,
108  std::vector<std::string>& filenames);
109 
110  std::string getName() const {
111  return name_;
112  }
113  // Delete the dir and all of its files/sub directories using C++ calls.
114  //
115  static bool removeDir( const char * dirName );
116 
117 
118  private:
119 
120  std::string name_;
121  };
122 } // End namespace SCIRun
123 
124 #ifdef _WIN32
125 // windows mkdir doesn't take permissions
126 # define MKDIR(dir, perm) mkdir(dir)
127 // windows doesn't have lstat
128 # define LSTAT(file, buf) stat(file, buf)
129 
130 #else
131 # define MKDIR(dir, perm) mkdir(dir, perm)
132 # define LSTAT(file, buf) lstat(file, buf)
133 #endif
134 
135 #endif
#define SCISHARE
Definition: share.h:39
std::string getName() const
Definition: Dir.h:110
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Definition: Dir.h:75