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