]>
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 const off_t wxInvalidOffset
= (off_t
)-1;
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
43 WXDLLEXPORT
bool wxFileExists(const wxString
& filename
);
44 #define FileExists wxFileExists
46 // does the path exist? (may have or not '/' or '\\' at the end)
47 WXDLLEXPORT
bool wxPathExists(const char *pszPathName
);
49 #define wxDirExists wxPathExists
50 #define DirExists wxDirExists
52 WXDLLEXPORT
bool wxIsAbsolutePath(const wxString
& filename
);
53 #define IsAbsolutePath wxIsAbsolutePath
56 WXDLLEXPORT
char* wxFileNameFromPath(char *path
);
57 WXDLLEXPORT wxString
wxFileNameFromPath(const wxString
& path
);
58 #define FileNameFromPath wxFileNameFromPath
61 WXDLLEXPORT
char* wxPathOnly(char *path
);
62 WXDLLEXPORT wxString
wxPathOnly(const wxString
& path
);
63 #define PathOnly wxPathOnly
66 WXDLLEXPORT wxString
wxRealPath(const wxString
& path
);
68 WXDLLEXPORT
void wxDos2UnixFilename(char *s
);
69 #define Dos2UnixFilename wxDos2UnixFilename
71 WXDLLEXPORT
void wxUnix2DosFilename(char *s
);
72 #define Unix2DosFilename wxUnix2DosFilename
74 // Strip the extension, in situ
75 WXDLLEXPORT
void wxStripExtension(char *buffer
);
76 WXDLLEXPORT
void wxStripExtension(wxString
& buffer
);
78 // Get a temporary filename, opening and closing the file.
79 WXDLLEXPORT
char* wxGetTempFileName(const wxString
& prefix
, char *buf
= (char *) NULL
);
81 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
82 WXDLLEXPORT
char* wxExpandPath(char *dest
, const char *path
);
84 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
85 // and make (if under the home tree) relative to home
86 // [caller must copy-- volatile]
87 WXDLLEXPORT
char* wxContractPath (const wxString
& filename
,
88 const wxString
& envname
= "", const wxString
& user
= "");
90 // Destructive removal of /./ and /../ stuff
91 WXDLLEXPORT
char* wxRealPath(char *path
);
93 // Allocate a copy of the full absolute path
94 WXDLLEXPORT
char* wxCopyAbsolutePath(const wxString
& path
);
96 // Get first file name matching given wild card.
97 // Flags are reserved for future use.
100 WXDLLEXPORT
char* wxFindFirstFile(const char *spec
, int flags
= wxFILE
);
101 WXDLLEXPORT
char* wxFindNextFile(void);
103 // Does the pattern contain wildcards?
104 WXDLLEXPORT
bool wxIsWild(const wxString
& pattern
);
106 // Does the pattern match the text (usually a filename)?
107 // If dot_special is TRUE, doesn't match * against . (eliminating
108 // `hidden' dot files)
109 WXDLLEXPORT
bool wxMatchWild(const wxString
& pattern
, const wxString
& text
, bool dot_special
= TRUE
);
111 // Concatenate two files to form third
112 WXDLLEXPORT
bool wxConcatFiles(const wxString
& file1
, const wxString
& file2
, const wxString
& file3
);
114 // Copy file1 to file2
115 WXDLLEXPORT
bool wxCopyFile(const wxString
& file1
, const wxString
& file2
);
118 WXDLLEXPORT
bool wxRemoveFile(const wxString
& file
);
121 WXDLLEXPORT
bool wxRenameFile(const wxString
& file1
, const wxString
& file2
);
123 // Get current working directory.
124 // If buf is NULL, allocates space using new, else
126 // IMPORTANT NOTE getcwd is know not to work under some releases
127 // of Win32s 1.3, according to MS release notes!
128 WXDLLEXPORT
char* wxGetWorkingDirectory(char *buf
= (char *) NULL
, int sz
= 1000);
130 // Set working directory
131 WXDLLEXPORT
bool wxSetWorkingDirectory(const wxString
& d
);
134 WXDLLEXPORT
bool wxMkdir(const wxString
& dir
);
136 // Remove directory. Flags reserved for future use.
137 WXDLLEXPORT
bool wxRmdir(const wxString
& dir
, int flags
= 0);
139 // separators in file names
140 #define FILE_SEP_EXT '.'
141 #define FILE_SEP_DSK ':'
142 #define FILE_SEP_PATH_DOS '\\'
143 #define FILE_SEP_PATH_UNIX '/'
145 // separator in the path list (as in PATH environment variable)
146 // NB: these are strings and not characters on purpose!
147 #define PATH_SEP_DOS ";"
148 #define PATH_SEP_UNIX ":"
150 // platform independent versions
152 #define FILE_SEP_PATH FILE_SEP_PATH_UNIX
153 #define PATH_SEP PATH_SEP_UNIX
155 #define FILE_SEP_PATH FILE_SEP_PATH_DOS
156 #define PATH_SEP PATH_SEP_DOS
157 #endif // Unix/Windows
159 // this is useful for wxString::IsSameAs(): to compare two file names use
160 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
162 #define wxARE_FILENAMES_CASE_SENSITIVE TRUE
164 #define wxARE_FILENAMES_CASE_SENSITIVE FALSE
165 #endif // Unix/Windows
167 // is the char a path separator?
168 inline bool wxIsPathSeparator(char c
)
169 { return c
== FILE_SEP_PATH_DOS
|| c
== FILE_SEP_PATH_UNIX
; }
171 // does the string ends with path separator?
172 WXDLLEXPORT
bool wxEndsWithPathSeparator(const char *pszFileName
);
174 // split the full path into path (including drive for DOS), name and extension
175 // (understands both '/' and '\\')
176 WXDLLEXPORT
void wxSplitPath(const char *pszFileName
,
181 // find a file in a list of directories, returns false if not found
182 WXDLLEXPORT
bool wxFindFileInPath(wxString
*pStr
, const char *pszPath
, const char *pszFile
);
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
189 class WXDLLEXPORT wxPathList
: public wxStringList
192 void AddEnvList(const wxString
& envVariable
); // Adds all paths in environment variable
193 void Add(const wxString
& path
);
194 wxString
FindValidPath(const wxString
& filename
); // Find the first full path
195 // for which the file exists
196 wxString
FindAbsoluteValidPath(const wxString
& filename
); // Find the first full path
197 // for which the file exists; ensure it's an absolute
198 // path that gets returned.
199 void EnsureFileAccessible(const wxString
& path
); // Given full path and filename,
201 bool Member(const wxString
& path
);
204 DECLARE_DYNAMIC_CLASS(wxPathList
)