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