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