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