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