3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "exceptions.h"
28 #define DIR_DELIM "\\"
29 #define DIR_DELIM_CHAR '\\'
30 #define FILESYS_CASE_INSENSITIVE true
31 #define PATH_DELIM ";"
34 #define DIR_DELIM_CHAR '/'
35 #define FILESYS_CASE_INSENSITIVE false
36 #define PATH_DELIM ":"
39 namespace irr { namespace io {
52 std::vector<DirListNode> GetDirListing(const std::string &path);
54 // Returns true if already exists
55 bool CreateDir(const std::string &path);
57 bool PathExists(const std::string &path);
59 bool IsPathAbsolute(const std::string &path);
61 bool IsDir(const std::string &path);
63 bool IsDirDelimiter(char c);
65 // Only pass full paths to this one. True on success.
66 // NOTE: The WIN32 version returns always true.
67 bool RecursiveDelete(const std::string &path);
69 bool DeleteSingleFileOrEmptyDirectory(const std::string &path);
71 // Returns path to temp directory, can return "" on error
72 std::string TempPath();
74 // Returns path to securely-created temporary file (will already exist when this function returns)
75 // can return "" on error
76 std::string CreateTempFile();
78 /* Returns a list of subdirectories, including the path itself, but excluding
79 hidden directories (whose names start with . or _)
81 void GetRecursiveDirs(std::vector<std::string> &dirs, const std::string &dir);
82 std::vector<std::string> GetRecursiveDirs(const std::string &dir);
86 /* The path itself not included, returns a list of all subpaths.
87 dst - vector that contains all the subpaths.
88 list files - include files in the list of subpaths.
89 ignore - paths that start with these charcters will not be listed.
91 void GetRecursiveSubPaths(const std::string &path,
92 std::vector<std::string> &dst,
94 const std::set<char> &ignore = {});
96 // Only pass full paths to this one. True on success.
97 bool RecursiveDeleteContent(const std::string &path);
99 // Create all directories on the given path that don't already exist.
100 bool CreateAllDirs(const std::string &path);
102 // Copy a regular file
103 bool CopyFileContents(const std::string &source, const std::string &target);
105 // Copy directory and all subdirectories
106 // Omits files and subdirectories that start with a period
107 bool CopyDir(const std::string &source, const std::string &target);
109 // Move directory and all subdirectories
110 // Behavior with files/subdirs that start with a period is undefined
111 bool MoveDir(const std::string &source, const std::string &target);
113 // Check if one path is prefix of another
114 // For example, "/tmp" is a prefix of "/tmp" and "/tmp/file" but not "/tmp2"
115 // Ignores case differences and '/' vs. '\\' on Windows
116 bool PathStartsWith(const std::string &path, const std::string &prefix);
118 // Remove last path component and the dir delimiter before and/or after it,
119 // returns "" if there is only one path component.
120 // removed: If non-NULL, receives the removed component(s).
121 // count: Number of components to remove
122 std::string RemoveLastPathComponent(const std::string &path,
123 std::string *removed = NULL, int count = 1);
125 // Remove "." and ".." path components and for every ".." removed, remove
126 // the last normal path component before it. Unlike AbsolutePath,
127 // this does not resolve symlinks and check for existence of directories.
128 std::string RemoveRelativePathComponents(std::string path);
130 // Returns the absolute path for the passed path, with "." and ".." path
131 // components and symlinks removed. Returns "" on error.
132 std::string AbsolutePath(const std::string &path);
134 // Returns the filename from a path or the entire path if no directory
135 // delimiter is found.
136 const char *GetFilenameFromPath(const char *path);
138 bool safeWriteToFile(const std::string &path, const std::string &content);
141 bool extractZipFile(irr::io::IFileSystem *fs, const char *filename, const std::string &destination);
144 bool ReadFile(const std::string &path, std::string &out);
146 bool Rename(const std::string &from, const std::string &to);