]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/filename.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileName - encapsulates a file path
4 // Author: Robert Roebling, Vadim Zeitlin
8 // Copyright: (c) 2000 Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FILENAME_H_
13 #define _WX_FILENAME_H_
16 #pragma interface "filename.h"
20 #include "wx/string.h"
26 1. support for drives under Windows
27 2. more file operations:
29 b) [acm]time() - get and set
31 d) file permissions with readable accessors for most common bits
32 such as IsReadable() &c
34 3. SameFileAs() function to compare inodes under Unix
37 // ridiculously enough, this will replace DirExists with wxDirExists etc
38 #include "wx/filefn.h"
39 #include "wx/datetime.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 // the various values for the path format: this mainly affects the path
46 // separator but also whether or not the path has the drive part (as under
50 wxPATH_NATIVE
= 0, // the path format for the current platform
55 wxPATH_BEOS
= wxPATH_UNIX
,
56 wxPATH_WIN
= wxPATH_DOS
,
57 wxPATH_OS2
= wxPATH_DOS
60 // the kind of normalization to do with the file name: these values can be
61 // or'd together to perform several operations at once
64 wxPATH_NORM_ENV_VARS
= 0x0001, // replace env vars with their values
65 wxPATH_NORM_DOTS
= 0x0002, // squeeze all .. and . and prepend cwd
66 wxPATH_NORM_TILDE
= 0x0004, // Unix only: replace ~ and ~user
67 wxPATH_NORM_CASE
= 0x0008, // if case insensitive => tolower
68 wxPATH_NORM_ABSOLUTE
= 0x0010, // make the path absolute
69 wxPATH_NORM_LONG
= 0x0020, // make the path the long form
70 wxPATH_NORM_ALL
= 0x003f
73 // ----------------------------------------------------------------------------
74 // wxFileName: encapsulates a file path
75 // ----------------------------------------------------------------------------
77 class WXDLLEXPORT wxFileName
80 // constructors and assignment
84 wxFileName( const wxFileName
&filepath
) { Assign(filepath
); }
86 // from a full filename: if it terminates with a '/', a directory path
87 // is contructed (the name will be empty), otherwise a file name and
88 // extension are extracted from it
89 wxFileName( const wxString
& fullpath
, wxPathFormat format
= wxPATH_NATIVE
)
90 { Assign( fullpath
, format
); }
92 // from a directory name and a file name
93 wxFileName(const wxString
& path
,
95 wxPathFormat format
= wxPATH_NATIVE
)
96 { Assign(path
, name
, format
); }
98 // from a directory name, file base name and extension
99 wxFileName(const wxString
& path
,
100 const wxString
& name
,
102 wxPathFormat format
= wxPATH_NATIVE
)
103 { Assign(path
, name
, ext
, format
); }
105 // assorted assignment operators
107 wxFileName
& operator=(const wxFileName
& filename
)
108 { Assign(filename
); return *this; }
110 wxFileName
& operator=(const wxString
& filename
)
111 { Assign(filename
); return *this; }
113 // the same for delayed initialization
115 // VZ: wouldn't it be better to call this Create() for consistency with
116 // all GUI classes? Personally, I like Set() more than Assign() too
118 void Assign(const wxFileName
& filepath
);
119 void Assign(const wxString
& fullpath
,
120 wxPathFormat format
= wxPATH_NATIVE
);
121 void Assign(const wxString
& path
,
122 const wxString
& name
,
123 wxPathFormat format
= wxPATH_NATIVE
);
124 void Assign(const wxString
& path
,
125 const wxString
& name
,
127 wxPathFormat format
= wxPATH_NATIVE
);
128 void AssignDir(const wxString
& dir
, wxPathFormat format
= wxPATH_NATIVE
)
129 { Assign(dir
, _T(""), format
); }
131 // reset all components to default, uninitialized state
134 // static pseudo constructors
135 static wxFileName
FileName(const wxString
& file
);
136 static wxFileName
DirName(const wxString
& dir
);
138 // test for existence
140 // is the filename valid at all?
141 bool IsOk() const { return !m_dirs
.IsEmpty() || !m_name
.IsEmpty(); }
143 // does the file with this name exists?
145 static bool FileExists( const wxString
&file
);
147 // does the directory with this name exists?
149 static bool DirExists( const wxString
&dir
);
151 // Well, get modification time with sec resolution
152 wxDateTime
GetModificationTime();
154 // VZ: also need: IsDirWritable(), IsFileExecutable() &c (TODO)
156 // various file/dir operations
158 // retrieve the value of the current working directory
160 static wxString
GetCwd();
162 // change the current working directory
164 static bool SetCwd( const wxString
&cwd
);
166 // get the value of user home (Unix only mainly)
167 void AssignHomeDir();
168 static wxString
GetHomeDir();
170 // get a temp file name starting with thespecified prefix
171 void AssignTempFileName( const wxString
&prefix
);
173 // directory creation and removal.
174 // if full is TRUE, will try to make each directory in the path.
175 bool Mkdir( int perm
= 0777, bool full
= FALSE
);
176 static bool Mkdir( const wxString
&dir
, int perm
= 0777, bool full
= FALSE
);
179 static bool Rmdir( const wxString
&dir
);
181 // operations on the path
183 // normalize the path: with the default flags value, the path will be
184 // made absolute, without any ".." and "." and all environment
185 // variables will be expanded in it
187 // this may be done using another (than current) value of cwd
188 bool Normalize(wxPathNormalize flags
= wxPATH_NORM_ALL
,
189 const wxString
& cwd
= wxEmptyString
,
190 wxPathFormat format
= wxPATH_NATIVE
);
194 // uses the current platform settings
195 bool operator==(const wxFileName
& filename
) { return SameAs(filename
); }
196 bool operator==(const wxString
& filename
)
197 { return *this == wxFileName(filename
); }
199 // compares with the rules of this platform
200 bool SameAs(const wxFileName
&filepath
,
201 wxPathFormat format
= wxPATH_NATIVE
);
204 static bool IsCaseSensitive( wxPathFormat format
= wxPATH_NATIVE
);
205 bool IsRelative( wxPathFormat format
= wxPATH_NATIVE
);
206 bool IsAbsolute( wxPathFormat format
= wxPATH_NATIVE
);
208 // get the string of path separators for this format
209 static wxString
GetPathSeparators(wxPathFormat format
= wxPATH_NATIVE
);
211 // is the char a path separator for this format?
212 static bool IsPathSeparator(wxChar ch
, wxPathFormat format
= wxPATH_NATIVE
);
214 // FIXME: what exactly does this do?
215 bool IsWild( wxPathFormat format
= wxPATH_NATIVE
);
218 void AppendDir( const wxString
&dir
);
219 void PrependDir( const wxString
&dir
);
220 void InsertDir( int before
, const wxString
&dir
);
221 void RemoveDir( int pos
);
222 size_t GetDirCount() const { return m_dirs
.GetCount(); }
225 void SetExt( const wxString
&ext
) { m_ext
= ext
; }
226 wxString
GetExt() const { return m_ext
; }
227 bool HasExt() const { return !m_ext
.IsEmpty(); }
229 void SetName( const wxString
&name
) { m_name
= name
; }
230 wxString
GetName() const { return m_name
; }
231 bool HasName() const { return !m_name
.IsEmpty(); }
233 // full name is the file name + extension (but without the path)
234 void SetFullName(const wxString
& fullname
);
235 wxString
GetFullName() const;
237 const wxArrayString
&GetDirs() const { return m_dirs
; }
239 // Construct path only - possibly with the trailing separator
240 wxString
GetPath( bool add_separator
= FALSE
,
241 wxPathFormat format
= wxPATH_NATIVE
) const;
243 // more readable synonym
244 wxString
GetPathWithSep(wxPathFormat format
= wxPATH_NATIVE
) const
245 { return GetPath(TRUE
/* add separator */, format
); }
247 // Construct full path with name and ext
248 wxString
GetFullPath( wxPathFormat format
= wxPATH_NATIVE
) const;
250 // Return the short form of the path (returns identity on non-Windows platforms)
251 wxString
GetShortPath() const;
253 // Return the long form of the path (returns identity on non-Windows platforms)
254 wxString
GetLongPath() const;
258 // get the canonical path format for this platform
259 static wxPathFormat
GetFormat( wxPathFormat format
= wxPATH_NATIVE
);
261 // split a fullpath into path, (base) name and ext (all of the pointers
263 static void SplitPath(const wxString
& fullpath
,
267 wxPathFormat format
= wxPATH_NATIVE
);
270 // the path components of the file
271 wxArrayString m_dirs
;
273 // the file name and extension (empty for directories)
278 #endif // _WX_FILENAME_H_