]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filefn.h
fixed typo
[wxWidgets.git] / include / wx / filefn.h
CommitLineData
c801d85f
KB
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
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _FILEFN_H_
13#define _FILEFN_H_
c801d85f 14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
7af89395 16 #pragma interface "filefn.h"
c801d85f
KB
17#endif
18
ed58dbea 19#include "wx/list.h"
b76069e2 20#include "wx/arrstr.h"
e49f47aa 21
0e0126c2 22#ifndef __WXWINCE__
a47ce4a7 23#include <time.h>
0e0126c2 24#endif
a47ce4a7 25
45ea509a
VZ
26// ----------------------------------------------------------------------------
27// constants
28// ----------------------------------------------------------------------------
c801d85f 29
0e0126c2
RR
30#ifdef __WXWINCE__
31 typedef long off_t;
32#else
33
45ea509a 34// define off_t
2d2ed20f 35#if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
7af89395 36 #include <sys/types.h>
17dff81c 37#else
7af89395 38 typedef long off_t;
17dff81c 39#endif
45ea509a 40
8be97d65 41#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined( __INTEL__) )
3f4a0c5b 42 typedef _off_t off_t;
2bdf7154 43#elif defined(__SYMANTEC__)
3f4a0c5b 44 typedef long off_t;
2d2ed20f 45#elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__)
8be97d65 46 typedef long off_t;
2432b92d
JS
47#endif
48
5d19b6ac
CE
49#endif
50
66b6b045
DW
51#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
52//
70862fa8 53// VisualAge C++ V4.0 cannot have any external linkage const decs
66b6b045
DW
54// in headers included by more than one primary source
55//
70862fa8
DW
56extern const off_t wxInvalidOffset;
57#else
1678ad78 58const off_t wxInvalidOffset = (off_t)-1;
66b6b045 59#endif
1678ad78 60
7af89395
VZ
61enum wxSeekMode
62{
45ea509a
VZ
63 wxFromStart,
64 wxFromCurrent,
65 wxFromEnd
7af89395 66};
45ea509a 67
f6bcfd97
BP
68// ----------------------------------------------------------------------------
69// declare our versions of low level file functions: some compilers prepend
70// underscores to the usual names, some also have Unicode versions of them
71// ----------------------------------------------------------------------------
72
73// Microsoft compiler loves underscores, feed them to it
fbdb357e 74#if defined( __VISUALC__ ) \
5283098e 75 || ( defined(__MINGW32__) && !defined(__WINE__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
18da7cf2 76 || ( defined(__MWERKS__) && defined(__WXMSW__) ) \
ba1e9d6c 77 || ( defined(__DMC__) && defined(__WXMSW__) ) \
18da7cf2 78 || ( defined(__WATCOMC__) && defined(__WXMSW__) )
f6bcfd97 79 // functions
18da7cf2 80#if defined(__BORLANDC__) || defined(__WATCOMC__)
a3bb1d14
CE
81 #define _tell tell
82#endif
f6bcfd97
BP
83 #define wxClose _close
84 #define wxRead _read
85 #define wxWrite _write
86 #define wxLseek _lseek
87 #define wxFsync _commit
88 #define wxEof _eof
89
90 #define wxTell _tell
91
92 #if wxUSE_UNICODE
6de5b599 93 #if wxUSE_UNICODE_MSLU
3e6477f4
CE
94 #define wxOpen wxMSLU__wopen
95
3d5231db
VS
96 #define wxAccess wxMSLU__waccess
97 #define wxMkDir wxMSLU__wmkdir
98 #define wxRmDir wxMSLU__wrmdir
99 #define wxStat wxMSLU__wstat
6de5b599
VS
100 #else
101 #define wxOpen _wopen
3d5231db
VS
102 #define wxAccess _waccess
103 #define wxMkDir _wmkdir
104 #define wxRmDir _wrmdir
105 #define wxStat _wstat
6de5b599 106 #endif
f6bcfd97 107 #else // !wxUSE_UNICODE
3e6477f4
CE
108#ifdef __BORLANDC__
109 #define wxOpen open
110#else
f6bcfd97 111 #define wxOpen _open
3e6477f4 112#endif
f6bcfd97 113 #define wxAccess _access
f6bcfd97 114 #define wxMkDir _mkdir
311ccb86
VZ
115#ifdef __WATCOMC__
116 #define wxRmDir rmdir
117#else
f6bcfd97 118 #define wxRmDir _rmdir
311ccb86 119#endif
f6bcfd97
BP
120 #define wxStat _stat
121 #endif
122
123 // types
18da7cf2
VZ
124#if defined(__WATCOMC__)&& wxUSE_UNICODE
125 #define wxStructStat struct _wstat
126#else
f6bcfd97 127 #define wxStructStat struct _stat
18da7cf2 128#endif
f6bcfd97
BP
129
130 // constants (unless already defined by the user code)
18da7cf2 131 #if !defined(O_RDONLY) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
f6bcfd97
BP
132 #define O_RDONLY _O_RDONLY
133 #define O_WRONLY _O_WRONLY
134 #define O_RDWR _O_RDWR
135 #define O_EXCL _O_EXCL
136 #define O_CREAT _O_CREAT
137 #define O_BINARY _O_BINARY
a3bb1d14 138 #endif
f6bcfd97 139
18da7cf2 140 #if !defined(__BORLANDC__) && !defined(__WATCOMC__)
f6bcfd97
BP
141 #define S_IFMT _S_IFMT
142 #define S_IFDIR _S_IFDIR
143 #define S_IFREG _S_IFREG
144 #endif // O_RDONLY
145#else
146 // functions
f6bcfd97
BP
147 #define wxClose close
148 #define wxRead read
149 #define wxWrite write
150 #define wxLseek lseek
151 #define wxFsync commit
f6bcfd97
BP
152 #define wxEof eof
153
154 #define wxMkDir mkdir
155 #define wxRmDir rmdir
156
157 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
158
f6bcfd97 159 #define wxStructStat struct stat
92980e90
RR
160
161#if wxUSE_UNICODE
162# define wxNEED_WX_UNISTD_H
c4e41ce3
SC
163#if defined(__MWERKS__) && defined(macintosh)
164 #include <sys/stat.h>
165#endif
ba1e9d6c
VZ
166#if defined(__DMC__)
167 typedef unsigned long mode_t;
168#endif
bddd7a8d
VZ
169WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
170WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
171WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
92980e90
RR
172#else
173 #define wxOpen open
174 #define wxStat stat
175 #define wxAccess access
176#endif
f6bcfd97
BP
177
178#endif // VC++
179
45ea509a
VZ
180// ----------------------------------------------------------------------------
181// functions
182// ----------------------------------------------------------------------------
bddd7a8d 183WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
c801d85f
KB
184
185// does the path exist? (may have or not '/' or '\\' at the end)
bddd7a8d 186WXDLLIMPEXP_BASE bool wxPathExists(const wxChar *pszPathName);
c801d85f 187
bddd7a8d 188WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
c801d85f
KB
189
190// Get filename
bddd7a8d
VZ
191WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
192WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
c801d85f
KB
193
194// Get directory
bddd7a8d 195WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
c801d85f
KB
196
197// wxString version
bddd7a8d 198WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path);
c801d85f 199
bddd7a8d 200WXDLLIMPEXP_BASE void wxDos2UnixFilename(wxChar *s);
c801d85f 201
bddd7a8d 202WXDLLIMPEXP_BASE void wxUnix2DosFilename(wxChar *s);
c801d85f
KB
203
204// Strip the extension, in situ
bddd7a8d
VZ
205WXDLLIMPEXP_BASE void wxStripExtension(wxChar *buffer);
206WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer);
c801d85f 207
ade35f11 208// Get a temporary filename
bddd7a8d
VZ
209WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = (wxChar *) NULL);
210WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf);
c801d85f
KB
211
212// Expand file name (~/ and ${OPENWINHOME}/ stuff)
bddd7a8d
VZ
213WXDLLIMPEXP_BASE wxChar* wxExpandPath(wxChar *dest, const wxChar *path);
214WXDLLIMPEXP_BASE bool wxExpandPath(wxString& dest, const wxChar *path);
c801d85f
KB
215
216// Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
217// and make (if under the home tree) relative to home
218// [caller must copy-- volatile]
bddd7a8d 219WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename,
ade35f11
VZ
220 const wxString& envname = wxEmptyString,
221 const wxString& user = wxEmptyString);
c801d85f
KB
222
223// Destructive removal of /./ and /../ stuff
bddd7a8d 224WXDLLIMPEXP_BASE wxChar* wxRealPath(wxChar *path);
c801d85f
KB
225
226// Allocate a copy of the full absolute path
bddd7a8d 227WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path);
c801d85f
KB
228
229// Get first file name matching given wild card.
230// Flags are reserved for future use.
231#define wxFILE 1
232#define wxDIR 2
bddd7a8d
VZ
233WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxChar *spec, int flags = wxFILE);
234WXDLLIMPEXP_BASE wxString wxFindNextFile();
c801d85f
KB
235
236// Does the pattern contain wildcards?
bddd7a8d 237WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
c801d85f
KB
238
239// Does the pattern match the text (usually a filename)?
240// If dot_special is TRUE, doesn't match * against . (eliminating
241// `hidden' dot files)
bddd7a8d 242WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE);
c801d85f
KB
243
244// Concatenate two files to form third
bddd7a8d 245WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
c801d85f
KB
246
247// Copy file1 to file2
bddd7a8d 248WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
4658c44e 249 bool overwrite = TRUE);
c801d85f
KB
250
251// Remove file
bddd7a8d 252WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
c801d85f
KB
253
254// Rename file
bddd7a8d 255WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2);
c801d85f
KB
256
257// Get current working directory.
258// If buf is NULL, allocates space using new, else
259// copies into buf.
260// IMPORTANT NOTE getcwd is know not to work under some releases
261// of Win32s 1.3, according to MS release notes!
bddd7a8d 262WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = (wxChar *) NULL, int sz = 1000);
7af89395
VZ
263// new and preferred version of wxGetWorkingDirectory
264// NB: can't have the same name because of overloading ambiguity
bddd7a8d 265WXDLLIMPEXP_BASE wxString wxGetCwd();
c801d85f
KB
266
267// Set working directory
bddd7a8d 268WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
c801d85f
KB
269
270// Make directory
bddd7a8d 271WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = 0777);
c801d85f
KB
272
273// Remove directory. Flags reserved for future use.
bddd7a8d 274WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
c801d85f 275
2b5f62a0
VZ
276// compatibility defines, don't use in new code
277#define wxDirExists wxPathExists
278
ff69a290 279// ----------------------------------------------------------------------------
c801d85f 280// separators in file names
ff69a290
VZ
281// ----------------------------------------------------------------------------
282
283// between file name and extension
223d09f6 284#define wxFILE_SEP_EXT wxT('.')
ff69a290
VZ
285
286// between drive/volume name and the path
223d09f6 287#define wxFILE_SEP_DSK wxT(':')
ff69a290
VZ
288
289// between the path components
223d09f6
KB
290#define wxFILE_SEP_PATH_DOS wxT('\\')
291#define wxFILE_SEP_PATH_UNIX wxT('/')
844f90fb 292#define wxFILE_SEP_PATH_MAC wxT(':')
ff69a290 293#define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
c801d85f
KB
294
295// separator in the path list (as in PATH environment variable)
03e11df5
GD
296// there is no PATH variable in Classic Mac OS so just use the
297// semicolon (it must be different from the file name separator)
c801d85f 298// NB: these are strings and not characters on purpose!
223d09f6
KB
299#define wxPATH_SEP_DOS wxT(";")
300#define wxPATH_SEP_UNIX wxT(":")
03e11df5 301#define wxPATH_SEP_MAC wxT(";")
c801d85f
KB
302
303// platform independent versions
28e5e577 304#if defined(__UNIX__) && !defined(__CYGWIN__) && !defined(__OS2__)
7af89395
VZ
305 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
306 #define wxPATH_SEP wxPATH_SEP_UNIX
844f90fb 307#elif defined(__MAC__)
bedaf53e 308 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
3369df87 309 #define wxPATH_SEP wxPATH_SEP_MAC
e02e8816 310#elif defined(__CYGWIN__) // Cygwin
3ffbc733
VZ
311 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
312 #define wxPATH_SEP wxPATH_SEP_UNIX
1777b9bb 313#else // Windows and OS/2
7af89395
VZ
314 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
315 #define wxPATH_SEP wxPATH_SEP_DOS
c801d85f
KB
316#endif // Unix/Windows
317
92abb45d
VZ
318// this is useful for wxString::IsSameAs(): to compare two file names use
319// filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
28e5e577 320#if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
92abb45d 321 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
3369df87 322#else // Windows, Mac OS and OS/2
92abb45d
VZ
323 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
324#endif // Unix/Windows
325
c801d85f 326// is the char a path separator?
9d2f3c71 327inline bool wxIsPathSeparator(wxChar c)
903b61cc
VZ
328{
329 // under DOS/Windows we should understand both Unix and DOS file separators
28e5e577 330#if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
903b61cc
VZ
331 return c == wxFILE_SEP_PATH;
332#else
333 return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
334#endif
335}
c801d85f
KB
336
337// does the string ends with path separator?
bddd7a8d 338WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxChar *pszFileName);
c801d85f 339
92abb45d
VZ
340// split the full path into path (including drive for DOS), name and extension
341// (understands both '/' and '\\')
bddd7a8d 342WXDLLIMPEXP_BASE void wxSplitPath(const wxChar *pszFileName,
92abb45d
VZ
343 wxString *pstrPath,
344 wxString *pstrName,
345 wxString *pstrExt);
346
c801d85f 347// find a file in a list of directories, returns false if not found
bddd7a8d 348WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxChar *pszPath, const wxChar *pszFile);
c801d85f 349
631f1bfe
JS
350// Get the OS directory if appropriate (such as the Windows directory).
351// On non-Windows platform, probably just return the empty string.
bddd7a8d 352WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
631f1bfe 353
a47ce4a7 354// Get file modification time
bddd7a8d 355WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
a47ce4a7 356
9e152a55
WS
357// Parses the wildCard, returning the number of filters.
358// Returns 0 if none or if there's a problem,
359// The arrays will contain an equal number of items found before the error.
360// wildCard is in the form:
361// "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
daf32463 362WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
9e152a55 363
45ea509a
VZ
364// ----------------------------------------------------------------------------
365// classes
366// ----------------------------------------------------------------------------
367
c801d85f 368// Path searching
bddd7a8d 369class WXDLLIMPEXP_BASE wxPathList : public wxStringList
c801d85f 370{
a6f6393c 371public:
df5168c4
MB
372 // avoid GCC warning about virtual functions w/o virtual dtor
373 virtual ~wxPathList() {}
374
7af89395
VZ
375 // Adds all paths in environment variable
376 void AddEnvList(const wxString& envVariable);
c330a2cf 377
a6f6393c 378 void Add(const wxString& path);
7af89395
VZ
379 // Find the first full path for which the file exists
380 wxString FindValidPath(const wxString& filename);
381 // Find the first full path for which the file exists; ensure it's an
382 // absolute path that gets returned.
383 wxString FindAbsoluteValidPath(const wxString& filename);
384 // Given full path and filename, add path to list
385 void EnsureFileAccessible(const wxString& path);
386 // Returns TRUE if the path is in the list
a6f6393c
VZ
387 bool Member(const wxString& path);
388
389private:
df5168c4 390 // DECLARE_DYNAMIC_CLASS(wxPathList)
c801d85f
KB
391};
392
393#endif
34138703 394 // _WX_FILEFN_H_