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