]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
Removed wxProp source files
[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 WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
45
46 // ----------------------------------------------------------------------------
47 // functions
48 // ----------------------------------------------------------------------------
49 WXDLLEXPORT bool wxFileExists(const wxString& filename);
50 #define FileExists wxFileExists
51
52 // does the path exist? (may have or not '/' or '\\' at the end)
53 WXDLLEXPORT bool wxPathExists(const char *pszPathName);
54
55 #define wxDirExists wxPathExists
56 #define DirExists wxDirExists
57
58 WXDLLEXPORT bool wxIsAbsolutePath(const wxString& filename);
59 #define IsAbsolutePath wxIsAbsolutePath
60
61 // Get filename
62 WXDLLEXPORT char* wxFileNameFromPath(char *path);
63 WXDLLEXPORT wxString wxFileNameFromPath(const wxString& path);
64 #define FileNameFromPath wxFileNameFromPath
65
66 // Get directory
67 WXDLLEXPORT char* wxPathOnly(char *path);
68 WXDLLEXPORT wxString wxPathOnly(const wxString& path);
69 #define PathOnly wxPathOnly
70
71 // wxString version
72 WXDLLEXPORT wxString wxRealPath(const wxString& path);
73
74 WXDLLEXPORT void wxDos2UnixFilename(char *s);
75 #define Dos2UnixFilename wxDos2UnixFilename
76
77 WXDLLEXPORT void wxUnix2DosFilename(char *s);
78 #define Unix2DosFilename wxUnix2DosFilename
79
80 // Strip the extension, in situ
81 WXDLLEXPORT void wxStripExtension(char *buffer);
82 WXDLLEXPORT void wxStripExtension(wxString& buffer);
83
84 // Get a temporary filename, opening and closing the file.
85 WXDLLEXPORT char* wxGetTempFileName(const wxString& prefix, char *buf = (char *) NULL);
86
87 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
88 WXDLLEXPORT char* wxExpandPath(char *dest, const char *path);
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]
93 WXDLLEXPORT char* wxContractPath (const wxString& filename,
94 const wxString& envname = wxEmptyString, const wxString& user = wxEmptyString);
95
96 // Destructive removal of /./ and /../ stuff
97 WXDLLEXPORT char* wxRealPath(char *path);
98
99 // Allocate a copy of the full absolute path
100 WXDLLEXPORT char* wxCopyAbsolutePath(const wxString& path);
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
106 WXDLLEXPORT char* wxFindFirstFile(const char *spec, int flags = wxFILE);
107 WXDLLEXPORT char* wxFindNextFile(void);
108
109 // Does the pattern contain wildcards?
110 WXDLLEXPORT bool wxIsWild(const wxString& pattern);
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)
115 WXDLLEXPORT bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE);
116
117 // Concatenate two files to form third
118 WXDLLEXPORT bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
119
120 // Copy file1 to file2
121 WXDLLEXPORT bool wxCopyFile(const wxString& file1, const wxString& file2);
122
123 // Remove file
124 WXDLLEXPORT bool wxRemoveFile(const wxString& file);
125
126 // Rename file
127 WXDLLEXPORT bool wxRenameFile(const wxString& file1, const wxString& file2);
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!
134 WXDLLEXPORT char* wxGetWorkingDirectory(char *buf = (char *) NULL, int sz = 1000);
135
136 // Set working directory
137 WXDLLEXPORT bool wxSetWorkingDirectory(const wxString& d);
138
139 // Make directory
140 WXDLLEXPORT bool wxMkdir(const wxString& dir);
141
142 // Remove directory. Flags reserved for future use.
143 WXDLLEXPORT bool wxRmdir(const wxString& dir, int flags = 0);
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
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
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?
178 WXDLLEXPORT bool wxEndsWithPathSeparator(const char *pszFileName);
179
180 // split the full path into path (including drive for DOS), name and extension
181 // (understands both '/' and '\\')
182 WXDLLEXPORT void wxSplitPath(const char *pszFileName,
183 wxString *pstrPath,
184 wxString *pstrName,
185 wxString *pstrExt);
186
187 // find a file in a list of directories, returns false if not found
188 WXDLLEXPORT bool wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile);
189
190 // ----------------------------------------------------------------------------
191 // classes
192 // ----------------------------------------------------------------------------
193
194 // Path searching
195 class WXDLLEXPORT wxPathList : public wxStringList
196 {
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)
211 };
212
213 #endif
214 // _WX_FILEFN_H_
215