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