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