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