]>
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"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
26 #include <sys/types.h>
32 #if defined(__BORLANDC__) && defined(__WIN16__)
36 const off_t wxInvalidOffset
= (off_t
)-1;
44 WXDLLEXPORT_DATA(extern const char*) wxEmptyString
;
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
49 WXDLLEXPORT
bool wxFileExists(const wxString
& filename
);
50 #define FileExists wxFileExists
52 // does the path exist? (may have or not '/' or '\\' at the end)
53 WXDLLEXPORT
bool wxPathExists(const char *pszPathName
);
55 #define wxDirExists wxPathExists
56 #define DirExists wxDirExists
58 WXDLLEXPORT
bool wxIsAbsolutePath(const wxString
& filename
);
59 #define IsAbsolutePath wxIsAbsolutePath
62 WXDLLEXPORT
char* wxFileNameFromPath(char *path
);
63 WXDLLEXPORT wxString
wxFileNameFromPath(const wxString
& path
);
64 #define FileNameFromPath wxFileNameFromPath
67 WXDLLEXPORT
char* wxPathOnly(char *path
);
68 WXDLLEXPORT wxString
wxPathOnly(const wxString
& path
);
69 #define PathOnly wxPathOnly
72 WXDLLEXPORT wxString
wxRealPath(const wxString
& path
);
74 WXDLLEXPORT
void wxDos2UnixFilename(char *s
);
75 #define Dos2UnixFilename wxDos2UnixFilename
77 WXDLLEXPORT
void wxUnix2DosFilename(char *s
);
78 #define Unix2DosFilename wxUnix2DosFilename
80 // Strip the extension, in situ
81 WXDLLEXPORT
void wxStripExtension(char *buffer
);
82 WXDLLEXPORT
void wxStripExtension(wxString
& buffer
);
84 // Get a temporary filename, opening and closing the file.
85 WXDLLEXPORT
char* wxGetTempFileName(const wxString
& prefix
, char *buf
= (char *) NULL
);
87 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
88 WXDLLEXPORT
char* wxExpandPath(char *dest
, const char *path
);
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
);
96 // Destructive removal of /./ and /../ stuff
97 WXDLLEXPORT
char* wxRealPath(char *path
);
99 // Allocate a copy of the full absolute path
100 WXDLLEXPORT
char* wxCopyAbsolutePath(const wxString
& path
);
102 // Get first file name matching given wild card.
103 // Flags are reserved for future use.
106 WXDLLEXPORT
char* wxFindFirstFile(const char *spec
, int flags
= wxFILE
);
107 WXDLLEXPORT
char* wxFindNextFile(void);
109 // Does the pattern contain wildcards?
110 WXDLLEXPORT
bool wxIsWild(const wxString
& pattern
);
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
);
117 // Concatenate two files to form third
118 WXDLLEXPORT
bool wxConcatFiles(const wxString
& file1
, const wxString
& file2
, const wxString
& file3
);
120 // Copy file1 to file2
121 WXDLLEXPORT
bool wxCopyFile(const wxString
& file1
, const wxString
& file2
);
124 WXDLLEXPORT
bool wxRemoveFile(const wxString
& file
);
127 WXDLLEXPORT
bool wxRenameFile(const wxString
& file1
, const wxString
& file2
);
129 // Get current working directory.
130 // If buf is NULL, allocates space using new, else
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);
136 // Set working directory
137 WXDLLEXPORT
bool wxSetWorkingDirectory(const wxString
& d
);
140 WXDLLEXPORT
bool wxMkdir(const wxString
& dir
);
142 // Remove directory. Flags reserved for future use.
143 WXDLLEXPORT
bool wxRmdir(const wxString
& dir
, int flags
= 0);
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 '/'
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 ":"
156 // platform independent versions
158 #define FILE_SEP_PATH FILE_SEP_PATH_UNIX
159 #define PATH_SEP PATH_SEP_UNIX
161 #define FILE_SEP_PATH FILE_SEP_PATH_DOS
162 #define PATH_SEP PATH_SEP_DOS
163 #endif // Unix/Windows
165 // this is useful for wxString::IsSameAs(): to compare two file names use
166 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
168 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
170 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
171 #endif // Unix/Windows
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
; }
177 // does the string ends with path separator?
178 WXDLLEXPORT
bool wxEndsWithPathSeparator(const char *pszFileName
);
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
,
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
);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
195 class WXDLLEXPORT wxPathList
: public wxStringList
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,
207 bool Member(const wxString
& path
);
210 DECLARE_DYNAMIC_CLASS(wxPathList
)