]>
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"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // the various values for the path format: this mainly affects the path
45 // separator but also whether or not the path has the drive part (as under
49 wxPATH_NATIVE
= 0, // the path format for the current platform
54 wxPATH_BEOS
= wxPATH_UNIX
,
55 wxPATH_WIN
= wxPATH_DOS
,
56 wxPATH_OS2
= wxPATH_DOS
59 // the kind of normalization to do with the file name: these values can be
60 // or'd together to perform several operations at once
63 wxPATH_NORM_ENV_VARS
= 0x0001, // replace env vars with their values
64 wxPATH_NORM_DOTS
= 0x0002, // squeeze all .. and . and prepend cwd
65 wxPATH_NORM_TILDE
= 0x0004, // Unix only: replace ~ and ~user
66 wxPATH_NORM_CASE
= 0x0008, // if case insensitive => tolower
67 wxPATH_NORM_ABSOLUTE
= 0x0010, // make the path absolute
68 wxPATH_NORM_ALL
= 0x001f
71 // ----------------------------------------------------------------------------
72 // wxFileName: encapsulates a file path
73 // ----------------------------------------------------------------------------
75 class WXDLLEXPORT wxFileName
78 // constructors and assignment
82 wxFileName( const wxFileName
&filepath
) { Assign(filepath
); }
84 // from a full filename: if it terminates with a '/', a directory path
85 // is contructed (the name will be empty), otherwise a file name and
86 // extension are extracted from it
87 wxFileName( const wxString
& fullpath
, wxPathFormat format
= wxPATH_NATIVE
)
88 { Assign( fullpath
, format
); }
90 // from a directory name and a file name
91 wxFileName(const wxString
& path
,
93 wxPathFormat format
= wxPATH_NATIVE
)
94 { Assign(path
, name
, format
); }
96 // from a directory name, file base name and extension
97 wxFileName(const wxString
& path
,
100 wxPathFormat format
= wxPATH_NATIVE
)
101 { Assign(path
, name
, ext
, format
); }
103 // assorted assignment operators
105 wxFileName
& operator=(const wxFileName
& filename
)
106 { Assign(filename
); return *this; }
108 wxFileName
& operator=(const wxString
& filename
)
109 { Assign(filename
); return *this; }
111 // the same for delayed initialization
113 // VZ: wouldn't it be better to call this Create() for consistency with
114 // all GUI classes? Personally, I like Set() more than Assign() too
116 void Assign(const wxFileName
& filepath
);
117 void Assign(const wxString
& fullpath
,
118 wxPathFormat format
= wxPATH_NATIVE
);
119 void Assign(const wxString
& path
,
120 const wxString
& name
,
121 wxPathFormat format
= wxPATH_NATIVE
);
122 void Assign(const wxString
& path
,
123 const wxString
& name
,
125 wxPathFormat format
= wxPATH_NATIVE
);
126 void AssignDir(const wxString
& dir
, wxPathFormat format
= wxPATH_NATIVE
)
127 { Assign(dir
, _T(""), format
); }
129 // reset all components to default, uninitialized state
132 // static pseudo constructors
133 static wxFileName
FileName(const wxString
& file
);
134 static wxFileName
DirName(const wxString
& dir
);
136 // test for existence
138 // is the filename valid at all?
139 bool IsOk() const { return !m_dirs
.IsEmpty() || !m_name
.IsEmpty(); }
141 // does the file with this name exists?
143 static bool FileExists( const wxString
&file
);
145 // does the directory with this name exists?
147 static bool DirExists( const wxString
&dir
);
149 // VZ: also need: IsDirWritable(), IsFileExecutable() &c (TODO)
151 // various file/dir operations
153 // retrieve the value of the current working directory
155 static wxString
GetCwd();
157 // change the current working directory
159 static bool SetCwd( const wxString
&cwd
);
161 // get the value of user home (Unix only mainly)
162 void AssignHomeDir();
163 static wxString
GetHomeDir();
165 // get a temp file name starting with thespecified prefix
166 void AssignTempFileName( const wxString
&prefix
);
168 // directory creation and removal
169 bool Mkdir( int perm
= 0777 );
170 static bool Mkdir( const wxString
&dir
, int perm
= 0777 );
173 static bool Rmdir( const wxString
&dir
);
175 // operations on the path
177 // normalize the path: with the default flags value, the path will be
178 // made absolute, without any ".." and "." and all environment
179 // variables will be expanded in it
181 // this may be done using another (than current) value of cwd
182 bool Normalize(wxPathNormalize flags
= wxPATH_NORM_ALL
,
183 const wxString
& cwd
= wxEmptyString
,
184 wxPathFormat format
= wxPATH_NATIVE
);
188 // uses the current platform settings
189 bool operator==(const wxFileName
& filename
) { return SameAs(filename
); }
190 bool operator==(const wxString
& filename
)
191 { return *this == wxFileName(filename
); }
193 // compares with the rules of this platform
194 bool SameAs(const wxFileName
&filepath
,
195 wxPathFormat format
= wxPATH_NATIVE
);
198 static bool IsCaseSensitive( wxPathFormat format
= wxPATH_NATIVE
);
199 bool IsRelative( wxPathFormat format
= wxPATH_NATIVE
);
200 bool IsAbsolute( wxPathFormat format
= wxPATH_NATIVE
);
202 // get the string of path separators for this format
203 static wxString
GetPathSeparators(wxPathFormat format
= wxPATH_NATIVE
);
205 // is the char a path separator for this format?
206 static bool IsPathSeparator(wxChar ch
, wxPathFormat format
= wxPATH_NATIVE
);
208 // FIXME: what exactly does this do?
209 bool IsWild( wxPathFormat format
= wxPATH_NATIVE
);
212 void AppendDir( const wxString
&dir
);
213 void PrependDir( const wxString
&dir
);
214 void InsertDir( int before
, const wxString
&dir
);
215 void RemoveDir( int pos
);
216 size_t GetDirCount() const { return m_dirs
.GetCount(); }
219 void SetExt( const wxString
&ext
) { m_ext
= ext
; }
220 wxString
GetExt() const { return m_ext
; }
221 bool HasExt() const { return !m_ext
.IsEmpty(); }
223 void SetName( const wxString
&name
) { m_name
= name
; }
224 wxString
GetName() const { return m_name
; }
225 bool HasName() const { return !m_name
.IsEmpty(); }
227 // full name is the file name + extension (but without the path)
228 void SetFullName(const wxString
& fullname
);
229 wxString
GetFullName() const;
231 const wxArrayString
&GetDirs() const { return m_dirs
; }
233 // Construct path only - possibly with the trailing separator
234 wxString
GetPath( bool add_separator
= FALSE
,
235 wxPathFormat format
= wxPATH_NATIVE
) const;
237 // more readable synonym
238 wxString
GetPathWithSep(wxPathFormat format
= wxPATH_NATIVE
) const
239 { return GetPath(TRUE
/* add separator */, format
); }
241 // Construct full path with name and ext
242 wxString
GetFullPath( wxPathFormat format
= wxPATH_NATIVE
) const;
246 // get the canonical path format for this platform
247 static wxPathFormat
GetFormat( wxPathFormat format
= wxPATH_NATIVE
);
249 // split a fullpath into path, (base) name and ext (all of the pointers
251 static void SplitPath(const wxString
& fullpath
,
255 wxPathFormat format
= wxPATH_NATIVE
);
258 // the path components of the file
259 wxArrayString m_dirs
;
261 // the file name and extension (empty for directories)
266 #endif // _WX_FILENAME_H_