wxFileName II. It actually works.
[wxWidgets.git] / include / wx / filename.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filename.h
3 // Purpose: wxFileName - encapsulates ice cream
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 28.12.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FILENAME_H_
13 #define _WX_FILENAME_H_
14
15 #ifdef __GNUG__
16 #pragma interface "filename.h"
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/string.h"
21 #endif
22
23 // ridiculously enough, this will replace DirExists with wxDirExists etc
24 #include "wx/filefn.h"
25
26 enum wxPathFormat
27 {
28 wxPATH_NATIVE = 0,
29 wxPATH_UNIX,
30 wxPATH_MAC,
31 wxPATH_DOS,
32
33 wxPATH_BEOS = wxPATH_UNIX,
34 wxPATH_WIN = wxPATH_DOS,
35 wxPATH_OS2 = wxPATH_DOS
36
37 };
38
39 class WXDLLEXPORT wxFileName
40 {
41 public:
42 // constructors and assignment
43 wxFileName()
44 { }
45 wxFileName( const wxFileName &filepath );
46 wxFileName( const wxString &path, bool dir_only = FALSE, wxPathFormat format = wxPATH_NATIVE )
47 { Assign( path, dir_only, format ); }
48 void Assign( const wxString &path, bool dir_only = FALSE, wxPathFormat format = wxPATH_NATIVE );
49 void Assign( const wxFileName &filepath );
50
51 // Only native form
52 bool FileExists();
53 static bool FileExists( const wxString &file );
54
55 bool DirExists();
56 static bool DirExists( const wxString &dir );
57
58 void AssignCwd();
59 static wxString GetCwd();
60
61 bool SetCwd();
62 static bool SetCwd( const wxString &cwd );
63
64 void AssignHomeDir();
65 static wxString GetHomeDir();
66
67 void AssignTempFileName( const wxString &prefix );
68
69 bool Mkdir( int perm = 0777 );
70 static bool Mkdir( const wxString &dir, int perm = 0777 );
71
72 bool Rmdir();
73 static bool Rmdir( const wxString &dir );
74
75 // Remove . and .. (under Unix ~ as well)
76 bool Normalize( const wxString &cwd = wxEmptyString, const wxString &home = wxEmptyString );
77
78 // Comparison
79 bool SameAs( const wxFileName &filepath, bool upper_case = TRUE );
80
81 // Tests
82 bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE );
83 bool IsRelative( wxPathFormat format = wxPATH_NATIVE );
84 bool IsAbsolute( wxPathFormat format = wxPATH_NATIVE );
85 bool IsWild( wxPathFormat format = wxPATH_NATIVE );
86
87 // Dir accessors
88 void AppendDir( const wxString &dir );
89 void PrependDir( const wxString &dir );
90 void InsertDir( int before, const wxString &dir );
91 void RemoveDir( int pos );
92 size_t GetDirCount() { return m_dirs.GetCount(); }
93
94 // Other accessors
95 void SetExt( const wxString &ext ) { m_ext = ext; }
96 wxString GetExt() const { return m_ext; }
97 bool HasExt() const { return !m_ext.IsEmpty(); }
98
99 void SetName( const wxString &name ) { m_name = name; }
100 wxString GetName() const { return m_name; }
101 bool HasName() const { return !m_name.IsEmpty(); }
102
103 // name and ext
104 void SetFullName( const wxString name, wxPathFormat format = wxPATH_NATIVE );
105 wxString GetFullName();
106
107 const wxArrayString &GetDirs() const { return m_dirs; }
108
109 // Construct path only
110 wxString GetPath( bool add_separator = FALSE, wxPathFormat format = wxPATH_NATIVE ) const;
111
112 // Construct full path with name and ext
113 wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const;
114
115
116 static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE );
117
118 private:
119 wxArrayString m_dirs;
120 wxString m_name;
121 wxString m_ext;
122 };
123
124
125
126 #endif // _WX_FFILENAME_H_
127