]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "filefn.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
29 #include <sys/types.h>
34 #if defined(__VISUALC__) || ( defined(__MWERKS__) && defined( __INTEL__) )
36 #elif defined(__BORLANDC__) && defined(__WIN16__)
40 #elif defined(__MWERKS__) && !defined(__INTEL__)
44 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
46 // VisualAge C++ V4.0 cannot have any const decs
47 // in headers included by more than one primary source
49 extern const off_t wxInvalidOffset
;
51 const off_t wxInvalidOffset
= (off_t
)-1;
61 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
66 WXDLLEXPORT
bool wxFileExists(const wxString
& filename
);
67 #define FileExists wxFileExists
69 // does the path exist? (may have or not '/' or '\\' at the end)
70 WXDLLEXPORT
bool wxPathExists(const wxChar
*pszPathName
);
72 #define wxDirExists wxPathExists
73 #define DirExists wxDirExists
75 WXDLLEXPORT
bool wxIsAbsolutePath(const wxString
& filename
);
76 #define IsAbsolutePath wxIsAbsolutePath
79 WXDLLEXPORT wxChar
* wxFileNameFromPath(wxChar
*path
);
80 WXDLLEXPORT wxString
wxFileNameFromPath(const wxString
& path
);
81 #define FileNameFromPath wxFileNameFromPath
84 WXDLLEXPORT wxString
wxPathOnly(const wxString
& path
);
85 #define PathOnly wxPathOnly
88 WXDLLEXPORT wxString
wxRealPath(const wxString
& path
);
90 WXDLLEXPORT
void wxDos2UnixFilename(wxChar
*s
);
91 #define Dos2UnixFilename wxDos2UnixFilename
93 WXDLLEXPORT
void wxUnix2DosFilename(wxChar
*s
);
94 #define Unix2DosFilename wxUnix2DosFilename
97 WXDLLEXPORT wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
) ;
98 WXDLLEXPORT wxString
wxMacFSSpec2UnixFilename( const FSSpec
*spec
) ;
99 WXDLLEXPORT
void wxUnixFilename2FSSpec( const char *path
, FSSpec
*spec
) ;
100 WXDLLEXPORT
void wxMacFilename2FSSpec( const char *path
, FSSpec
*spec
) ;
101 WXDLLEXPORT wxString
wxMac2UnixFilename( const char *s
) ;
102 WXDLLEXPORT wxString
wxUnix2MacFilename( const char *s
);
105 // Strip the extension, in situ
106 WXDLLEXPORT
void wxStripExtension(wxChar
*buffer
);
107 WXDLLEXPORT
void wxStripExtension(wxString
& buffer
);
109 // Get a temporary filename, opening and closing the file.
110 WXDLLEXPORT wxChar
* wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
= (wxChar
*) NULL
);
111 WXDLLEXPORT
bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
);
113 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
114 WXDLLEXPORT wxChar
* wxExpandPath(wxChar
*dest
, const wxChar
*path
);
115 WXDLLEXPORT
bool wxExpandPath(wxString
& dest
, const wxChar
*path
);
117 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
118 // and make (if under the home tree) relative to home
119 // [caller must copy-- volatile]
120 WXDLLEXPORT wxChar
* wxContractPath(const wxString
& filename
,
121 const wxString
& envname
= wxEmptyString
,
122 const wxString
& user
= wxEmptyString
);
124 // Destructive removal of /./ and /../ stuff
125 WXDLLEXPORT wxChar
* wxRealPath(wxChar
*path
);
127 // Allocate a copy of the full absolute path
128 WXDLLEXPORT wxChar
* wxCopyAbsolutePath(const wxString
& path
);
130 // Get first file name matching given wild card.
131 // Flags are reserved for future use.
134 WXDLLEXPORT wxString
wxFindFirstFile(const wxChar
*spec
, int flags
= wxFILE
);
135 WXDLLEXPORT wxString
wxFindNextFile();
137 // Does the pattern contain wildcards?
138 WXDLLEXPORT
bool wxIsWild(const wxString
& pattern
);
140 // Does the pattern match the text (usually a filename)?
141 // If dot_special is TRUE, doesn't match * against . (eliminating
142 // `hidden' dot files)
143 WXDLLEXPORT
bool wxMatchWild(const wxString
& pattern
, const wxString
& text
, bool dot_special
= TRUE
);
145 // Concatenate two files to form third
146 WXDLLEXPORT
bool wxConcatFiles(const wxString
& file1
, const wxString
& file2
, const wxString
& file3
);
148 // Copy file1 to file2
149 WXDLLEXPORT
bool wxCopyFile(const wxString
& file1
, const wxString
& file2
);
152 WXDLLEXPORT
bool wxRemoveFile(const wxString
& file
);
155 WXDLLEXPORT
bool wxRenameFile(const wxString
& file1
, const wxString
& file2
);
157 // Get current working directory.
158 // If buf is NULL, allocates space using new, else
160 // IMPORTANT NOTE getcwd is know not to work under some releases
161 // of Win32s 1.3, according to MS release notes!
162 WXDLLEXPORT wxChar
* wxGetWorkingDirectory(wxChar
*buf
= (wxChar
*) NULL
, int sz
= 1000);
163 // new and preferred version of wxGetWorkingDirectory
164 // NB: can't have the same name because of overloading ambiguity
165 WXDLLEXPORT wxString
wxGetCwd();
167 // Set working directory
168 WXDLLEXPORT
bool wxSetWorkingDirectory(const wxString
& d
);
171 WXDLLEXPORT
bool wxMkdir(const wxString
& dir
, int perm
= 0777);
173 // Remove directory. Flags reserved for future use.
174 WXDLLEXPORT
bool wxRmdir(const wxString
& dir
, int flags
= 0);
176 // separators in file names
177 #define wxFILE_SEP_EXT wxT('.')
178 #define wxFILE_SEP_DSK wxT(':')
179 #define wxFILE_SEP_PATH_DOS wxT('\\')
180 #define wxFILE_SEP_PATH_UNIX wxT('/')
182 // separator in the path list (as in PATH environment variable)
183 // NB: these are strings and not characters on purpose!
184 #define wxPATH_SEP_DOS wxT(";")
185 #define wxPATH_SEP_UNIX wxT(":")
187 // platform independent versions
189 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
190 #define wxPATH_SEP wxPATH_SEP_UNIX
191 #else // Windows and OS/2
192 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
193 #define wxPATH_SEP wxPATH_SEP_DOS
194 #endif // Unix/Windows
196 // this is useful for wxString::IsSameAs(): to compare two file names use
197 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
199 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
200 #else // Windows and OS/2
201 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
202 #endif // Unix/Windows
204 // is the char a path separator?
205 inline bool wxIsPathSeparator(wxChar c
)
206 { return c
== wxFILE_SEP_PATH_DOS
|| c
== wxFILE_SEP_PATH_UNIX
; }
208 // does the string ends with path separator?
209 WXDLLEXPORT
bool wxEndsWithPathSeparator(const wxChar
*pszFileName
);
211 // split the full path into path (including drive for DOS), name and extension
212 // (understands both '/' and '\\')
213 WXDLLEXPORT
void wxSplitPath(const wxChar
*pszFileName
,
218 // find a file in a list of directories, returns false if not found
219 WXDLLEXPORT
bool wxFindFileInPath(wxString
*pStr
, const wxChar
*pszPath
, const wxChar
*pszFile
);
221 // Get the OS directory if appropriate (such as the Windows directory).
222 // On non-Windows platform, probably just return the empty string.
223 WXDLLEXPORT wxString
wxGetOSDirectory();
225 // Get file modification time
226 WXDLLEXPORT
time_t wxFileModificationTime(const wxString
& filename
);
228 // ----------------------------------------------------------------------------
230 // ----------------------------------------------------------------------------
233 class WXDLLEXPORT wxPathList
: public wxStringList
236 // Adds all paths in environment variable
237 void AddEnvList(const wxString
& envVariable
);
239 void Add(const wxString
& path
);
240 // Avoid compiler warning
241 wxNode
*Add(const wxChar
*s
) { return wxStringList::Add(s
); }
242 // Find the first full path for which the file exists
243 wxString
FindValidPath(const wxString
& filename
);
244 // Find the first full path for which the file exists; ensure it's an
245 // absolute path that gets returned.
246 wxString
FindAbsoluteValidPath(const wxString
& filename
);
247 // Given full path and filename, add path to list
248 void EnsureFileAccessible(const wxString
& path
);
249 // Returns TRUE if the path is in the list
250 bool Member(const wxString
& path
);
253 DECLARE_DYNAMIC_CLASS(wxPathList
)