]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
now wxToolBarGTK is #define'd as wxToolBar under wxGTK and not vice versa
[wxWidgets.git] / include / wx / filefn.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filefn.h
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __FILEFNH__
13 #define __FILEFNH__
14
15 #ifdef __GNUG__
16 #pragma interface "filefn.h"
17 #endif
18
19 #include <wx/list.h>
20
21 // ----------------------------------------------------------------------------
22 // constants
23 // ----------------------------------------------------------------------------
24
25 // define off_t
26 #include <sys/types.h>
27
28 #ifdef _MSC_VER
29 #define off_t _off_t
30 #endif
31
32 typedef enum {
33 wxFromStart,
34 wxFromCurrent,
35 wxFromEnd
36 } wxSeekMode;
37
38 // ----------------------------------------------------------------------------
39 // functions
40 // ----------------------------------------------------------------------------
41 bool WXDLLEXPORT wxFileExists(const wxString& filename);
42 #define FileExists wxFileExists
43
44 // does the path exist? (may have or not '/' or '\\' at the end)
45 bool WXDLLEXPORT wxPathExists(const char *pszPathName);
46
47 #define wxDirExists wxPathExists
48 #define DirExists wxDirExists
49
50 bool WXDLLEXPORT wxIsAbsolutePath(const wxString& filename);
51 #define IsAbsolutePath wxIsAbsolutePath
52
53 // Get filename
54 char* WXDLLEXPORT wxFileNameFromPath(char *path);
55 wxString WXDLLEXPORT wxFileNameFromPath(const wxString& path);
56 #define FileNameFromPath wxFileNameFromPath
57
58 // Get directory
59 char* WXDLLEXPORT wxPathOnly(char *path);
60 wxString WXDLLEXPORT wxPathOnly(const wxString& path);
61 #define PathOnly wxPathOnly
62
63 // wxString version
64 wxString WXDLLEXPORT wxRealPath(const wxString& path);
65
66 void WXDLLEXPORT wxDos2UnixFilename(char *s);
67 #define Dos2UnixFilename wxDos2UnixFilename
68
69 void WXDLLEXPORT wxUnix2DosFilename(char *s);
70 #define Unix2DosFilename wxUnix2DosFilename
71
72 // Strip the extension, in situ
73 void WXDLLEXPORT wxStripExtension(char *buffer);
74 void WXDLLEXPORT wxStripExtension(wxString& buffer);
75
76 // Get a temporary filename, opening and closing the file.
77 char* WXDLLEXPORT wxGetTempFileName(const wxString& prefix, char *buf = NULL);
78
79 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
80 char* WXDLLEXPORT wxExpandPath(char *dest, const char *path);
81
82 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
83 // and make (if under the home tree) relative to home
84 // [caller must copy-- volatile]
85 char* WXDLLEXPORT wxContractPath (const wxString& filename,
86 const wxString& envname = "", const wxString& user = "");
87
88 // Destructive removal of /./ and /../ stuff
89 char* WXDLLEXPORT wxRealPath(char *path);
90
91 // Allocate a copy of the full absolute path
92 char* WXDLLEXPORT wxCopyAbsolutePath(const wxString& path);
93
94 // Get first file name matching given wild card.
95 // Flags are reserved for future use.
96 #define wxFILE 1
97 #define wxDIR 2
98 char* WXDLLEXPORT wxFindFirstFile(const char *spec, int flags = wxFILE);
99 char* WXDLLEXPORT wxFindNextFile(void);
100
101 // Does the pattern contain wildcards?
102 bool WXDLLEXPORT wxIsWild(const wxString& pattern);
103
104 // Does the pattern match the text (usually a filename)?
105 // If dot_special is TRUE, doesn't match * against . (eliminating
106 // `hidden' dot files)
107 bool WXDLLEXPORT wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE);
108
109 // Concatenate two files to form third
110 bool WXDLLEXPORT wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
111
112 // Copy file1 to file2
113 bool WXDLLEXPORT wxCopyFile(const wxString& file1, const wxString& file2);
114
115 // Remove file
116 bool WXDLLEXPORT wxRemoveFile(const wxString& file);
117
118 // Rename file
119 bool WXDLLEXPORT wxRenameFile(const wxString& file1, const wxString& file2);
120
121 // Get current working directory.
122 // If buf is NULL, allocates space using new, else
123 // copies into buf.
124 // IMPORTANT NOTE getcwd is know not to work under some releases
125 // of Win32s 1.3, according to MS release notes!
126 char* WXDLLEXPORT wxGetWorkingDirectory(char *buf = NULL, int sz = 1000);
127
128 // Set working directory
129 bool WXDLLEXPORT wxSetWorkingDirectory(const wxString& d);
130
131 // Make directory
132 bool WXDLLEXPORT wxMkdir(const wxString& dir);
133
134 // Remove directory. Flags reserved for future use.
135 bool WXDLLEXPORT wxRmdir(const wxString& dir, int flags = 0);
136
137 // separators in file names
138 #define FILE_SEP_EXT '.'
139 #define FILE_SEP_DSK ':'
140 #define FILE_SEP_PATH_DOS '\\'
141 #define FILE_SEP_PATH_UNIX '/'
142
143 // separator in the path list (as in PATH environment variable)
144 // NB: these are strings and not characters on purpose!
145 #define PATH_SEP_DOS ";"
146 #define PATH_SEP_UNIX ":"
147
148 // platform independent versions
149 #ifdef __UNIX__
150 #define FILE_SEP_PATH FILE_SEP_PATH_UNIX
151 #define PATH_SEP PATH_SEP_UNIX
152 #else // Windows
153 #define FILE_SEP_PATH FILE_SEP_PATH_DOS
154 #define PATH_SEP PATH_SEP_DOS
155 #endif // Unix/Windows
156
157 // this is useful for wxString::IsSameAs(): to compare two file names use
158 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
159 #ifdef __UNIX__
160 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
161 #else // Windows
162 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
163 #endif // Unix/Windows
164
165 // is the char a path separator?
166 inline bool wxIsPathSeparator(char c)
167 { return c == FILE_SEP_PATH_DOS || c == FILE_SEP_PATH_UNIX; }
168
169 // does the string ends with path separator?
170 bool WXDLLEXPORT wxEndsWithPathSeparator(const char *pszFileName);
171
172 // split the full path into path (including drive for DOS), name and extension
173 // (understands both '/' and '\\')
174 void WXDLLEXPORT wxSplitPath(const char *pszFileName,
175 wxString *pstrPath,
176 wxString *pstrName,
177 wxString *pstrExt);
178
179 // find a file in a list of directories, returns false if not found
180 bool WXDLLEXPORT wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile);
181
182 // ----------------------------------------------------------------------------
183 // classes
184 // ----------------------------------------------------------------------------
185
186 // Path searching
187 class WXDLLEXPORT wxPathList: public wxStringList
188 {
189 DECLARE_DYNAMIC_CLASS(wxPathList)
190
191 public:
192 void AddEnvList(const wxString& envVariable); // Adds all paths in environment variable
193 void Add(const wxString& path);
194 wxString FindValidPath(const wxString& filename); // Find the first full path
195 // for which the file exists
196 wxString FindAbsoluteValidPath(const wxString& filename); // Find the first full path
197 // for which the file exists; ensure it's an absolute
198 // path that gets returned.
199 void EnsureFileAccessible(const wxString& path); // Given full path and filename,
200 // add path to list
201 bool Member(const wxString& path);
202 };
203
204 #endif
205 // __FILEFNH__
206