]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
8131e55c3f906f6c4afe373e3daeb5a3a1fca041
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 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
47 WXDLLEXPORT
bool wxFileExists(const wxString
& filename
);
48 #define FileExists wxFileExists
50 // does the path exist? (may have or not '/' or '\\' at the end)
51 WXDLLEXPORT
bool wxPathExists(const char *pszPathName
);
53 #define wxDirExists wxPathExists
54 #define DirExists wxDirExists
56 WXDLLEXPORT
bool wxIsAbsolutePath(const wxString
& filename
);
57 #define IsAbsolutePath wxIsAbsolutePath
60 WXDLLEXPORT
char* wxFileNameFromPath(char *path
);
61 WXDLLEXPORT wxString
wxFileNameFromPath(const wxString
& path
);
62 #define FileNameFromPath wxFileNameFromPath
65 WXDLLEXPORT
char* wxPathOnly(char *path
);
66 WXDLLEXPORT wxString
wxPathOnly(const wxString
& path
);
67 #define PathOnly wxPathOnly
70 WXDLLEXPORT wxString
wxRealPath(const wxString
& path
);
72 WXDLLEXPORT
void wxDos2UnixFilename(char *s
);
73 #define Dos2UnixFilename wxDos2UnixFilename
75 WXDLLEXPORT
void wxUnix2DosFilename(char *s
);
76 #define Unix2DosFilename wxUnix2DosFilename
78 // Strip the extension, in situ
79 WXDLLEXPORT
void wxStripExtension(char *buffer
);
80 WXDLLEXPORT
void wxStripExtension(wxString
& buffer
);
82 // Get a temporary filename, opening and closing the file.
83 WXDLLEXPORT
char* wxGetTempFileName(const wxString
& prefix
, char *buf
= (char *) NULL
);
85 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
86 WXDLLEXPORT
char* wxExpandPath(char *dest
, const char *path
);
88 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
89 // and make (if under the home tree) relative to home
90 // [caller must copy-- volatile]
91 WXDLLEXPORT
char* wxContractPath (const wxString
& filename
,
92 const wxString
& envname
= wxEmptyString
, const wxString
& user
= wxEmptyString
);
94 // Destructive removal of /./ and /../ stuff
95 WXDLLEXPORT
char* wxRealPath(char *path
);
97 // Allocate a copy of the full absolute path
98 WXDLLEXPORT
char* wxCopyAbsolutePath(const wxString
& path
);
100 // Get first file name matching given wild card.
101 // Flags are reserved for future use.
104 WXDLLEXPORT
char* wxFindFirstFile(const char *spec
, int flags
= wxFILE
);
105 WXDLLEXPORT
char* wxFindNextFile(void);
107 // Does the pattern contain wildcards?
108 WXDLLEXPORT
bool wxIsWild(const wxString
& pattern
);
110 // Does the pattern match the text (usually a filename)?
111 // If dot_special is TRUE, doesn't match * against . (eliminating
112 // `hidden' dot files)
113 WXDLLEXPORT
bool wxMatchWild(const wxString
& pattern
, const wxString
& text
, bool dot_special
= TRUE
);
115 // Concatenate two files to form third
116 WXDLLEXPORT
bool wxConcatFiles(const wxString
& file1
, const wxString
& file2
, const wxString
& file3
);
118 // Copy file1 to file2
119 WXDLLEXPORT
bool wxCopyFile(const wxString
& file1
, const wxString
& file2
);
122 WXDLLEXPORT
bool wxRemoveFile(const wxString
& file
);
125 WXDLLEXPORT
bool wxRenameFile(const wxString
& file1
, const wxString
& file2
);
127 // Get current working directory.
128 // If buf is NULL, allocates space using new, else
130 // IMPORTANT NOTE getcwd is know not to work under some releases
131 // of Win32s 1.3, according to MS release notes!
132 WXDLLEXPORT
char* wxGetWorkingDirectory(char *buf
= (char *) NULL
, int sz
= 1000);
134 // Set working directory
135 WXDLLEXPORT
bool wxSetWorkingDirectory(const wxString
& d
);
138 WXDLLEXPORT
bool wxMkdir(const wxString
& dir
);
140 // Remove directory. Flags reserved for future use.
141 WXDLLEXPORT
bool wxRmdir(const wxString
& dir
, int flags
= 0);
143 // separators in file names
144 #define FILE_SEP_EXT '.'
145 #define FILE_SEP_DSK ':'
146 #define FILE_SEP_PATH_DOS '\\'
147 #define FILE_SEP_PATH_UNIX '/'
149 // separator in the path list (as in PATH environment variable)
150 // NB: these are strings and not characters on purpose!
151 #define PATH_SEP_DOS ";"
152 #define PATH_SEP_UNIX ":"
154 // platform independent versions
156 #define FILE_SEP_PATH FILE_SEP_PATH_UNIX
157 #define PATH_SEP PATH_SEP_UNIX
159 #define FILE_SEP_PATH FILE_SEP_PATH_DOS
160 #define PATH_SEP PATH_SEP_DOS
161 #endif // Unix/Windows
163 // this is useful for wxString::IsSameAs(): to compare two file names use
164 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
166 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
168 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
169 #endif // Unix/Windows
171 // is the char a path separator?
172 inline bool wxIsPathSeparator(char c
)
173 { return c
== FILE_SEP_PATH_DOS
|| c
== FILE_SEP_PATH_UNIX
; }
175 // does the string ends with path separator?
176 WXDLLEXPORT
bool wxEndsWithPathSeparator(const char *pszFileName
);
178 // split the full path into path (including drive for DOS), name and extension
179 // (understands both '/' and '\\')
180 WXDLLEXPORT
void wxSplitPath(const char *pszFileName
,
185 // find a file in a list of directories, returns false if not found
186 WXDLLEXPORT
bool wxFindFileInPath(wxString
*pStr
, const char *pszPath
, const char *pszFile
);
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
193 class WXDLLEXPORT wxPathList
: public wxStringList
196 void AddEnvList(const wxString
& envVariable
); // Adds all paths in environment variable
197 void Add(const wxString
& path
);
198 wxString
FindValidPath(const wxString
& filename
); // Find the first full path
199 // for which the file exists
200 wxString
FindAbsoluteValidPath(const wxString
& filename
); // Find the first full path
201 // for which the file exists; ensure it's an absolute
202 // path that gets returned.
203 void EnsureFileAccessible(const wxString
& path
); // Given full path and filename,
205 bool Member(const wxString
& path
);
208 DECLARE_DYNAMIC_CLASS(wxPathList
)