]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
Various bug fixes, cosmetic changes
[wxWidgets.git] / include / wx / filefn.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filefn.h
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __FILEFNH__
13 #define __FILEFNH__
14
15 #ifdef __GNUG__
16 #pragma interface "filefn.h"
17 #endif
18
19 #include "wx/list.h"
20
21 bool WXDLLEXPORT wxFileExists(const wxString& filename);
22 #define FileExists wxFileExists
23
24 // does the path exist? (may have or not '/' or '\\' at the end)
25 bool WXDLLEXPORT wxPathExists(const char *pszPathName);
26
27 #define wxDirExists wxPathExists
28 #define DirExists wxDirExists
29
30 bool WXDLLEXPORT wxIsAbsolutePath(const wxString& filename);
31 #define IsAbsolutePath wxIsAbsolutePath
32
33 // Get filename
34 char* WXDLLEXPORT wxFileNameFromPath(char *path);
35 wxString WXDLLEXPORT wxFileNameFromPath(const wxString& path);
36 #define FileNameFromPath wxFileNameFromPath
37
38 // Get directory
39 char* WXDLLEXPORT wxPathOnly(char *path);
40 wxString WXDLLEXPORT wxPathOnly(const wxString& path);
41 #define PathOnly wxPathOnly
42
43 // wxString version
44 wxString WXDLLEXPORT wxRealPath(const wxString& path);
45
46 void WXDLLEXPORT wxDos2UnixFilename(char *s);
47 #define Dos2UnixFilename wxDos2UnixFilename
48
49 void WXDLLEXPORT wxUnix2DosFilename(char *s);
50 #define Unix2DosFilename wxUnix2DosFilename
51
52 // Strip the extension, in situ
53 void WXDLLEXPORT wxStripExtension(char *buffer);
54
55 // Get a temporary filename, opening and closing the file.
56 char* WXDLLEXPORT wxGetTempFileName(const wxString& prefix, char *buf = NULL);
57
58 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
59 char* WXDLLEXPORT wxExpandPath(char *dest, const char *path);
60
61 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
62 // and make (if under the home tree) relative to home
63 // [caller must copy-- volatile]
64 char* WXDLLEXPORT wxContractPath (const wxString& filename,
65 const wxString& envname = "", const wxString& user = "");
66
67 // Destructive removal of /./ and /../ stuff
68 char* WXDLLEXPORT wxRealPath(char *path);
69
70 // Allocate a copy of the full absolute path
71 char* WXDLLEXPORT wxCopyAbsolutePath(const wxString& path);
72
73 // Get first file name matching given wild card.
74 // Flags are reserved for future use.
75 #define wxFILE 1
76 #define wxDIR 2
77 char* WXDLLEXPORT wxFindFirstFile(const char *spec, int flags = wxFILE);
78 char* WXDLLEXPORT wxFindNextFile(void);
79
80 // Does the pattern contain wildcards?
81 bool WXDLLEXPORT wxIsWild(const wxString& pattern);
82
83 // Does the pattern match the text (usually a filename)?
84 // If dot_special is TRUE, doesn't match * against . (eliminating
85 // `hidden' dot files)
86 bool WXDLLEXPORT wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE);
87
88 // Concatenate two files to form third
89 bool WXDLLEXPORT wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
90
91 // Copy file1 to file2
92 bool WXDLLEXPORT wxCopyFile(const wxString& file1, const wxString& file2);
93
94 // Remove file
95 bool WXDLLEXPORT wxRemoveFile(const wxString& file);
96
97 // Rename file
98 bool WXDLLEXPORT wxRenameFile(const wxString& file1, const wxString& file2);
99
100 // Get current working directory.
101 // If buf is NULL, allocates space using new, else
102 // copies into buf.
103 // IMPORTANT NOTE getcwd is know not to work under some releases
104 // of Win32s 1.3, according to MS release notes!
105 char* WXDLLEXPORT wxGetWorkingDirectory(char *buf = NULL, int sz = 1000);
106
107 // Set working directory
108 bool WXDLLEXPORT wxSetWorkingDirectory(const wxString& d);
109
110 // Make directory
111 bool WXDLLEXPORT wxMkdir(const wxString& dir);
112
113 // Remove directory. Flags reserved for future use.
114 bool WXDLLEXPORT wxRmdir(const wxString& dir, int flags = 0);
115
116 // separators in file names
117 #define FILE_SEP_EXT '.'
118 #define FILE_SEP_DSK ':'
119 #define FILE_SEP_PATH_DOS '\\'
120 #define FILE_SEP_PATH_UNIX '/'
121
122 // separator in the path list (as in PATH environment variable)
123 // NB: these are strings and not characters on purpose!
124 #define PATH_SEP_DOS ";"
125 #define PATH_SEP_UNIX ":"
126
127 // platform independent versions
128 #ifdef __UNIX__
129 #define FILE_SEP_PATH FILE_SEP_PATH_UNIX
130 #define PATH_SEP PATH_SEP_UNIX
131 #else // Windows
132 #define FILE_SEP_PATH FILE_SEP_PATH_DOS
133 #define PATH_SEP PATH_SEP_DOS
134 #endif // Unix/Windows
135
136 // is the char a path separator?
137 inline bool wxIsPathSeparator(char c)
138 { return c == FILE_SEP_PATH_DOS || c == FILE_SEP_PATH_UNIX; }
139
140 // does the string ends with path separator?
141 bool WXDLLEXPORT wxEndsWithPathSeparator(const char *pszFileName);
142
143 // find a file in a list of directories, returns false if not found
144 bool WXDLLEXPORT wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile);
145
146 // Path searching
147 class WXDLLEXPORT wxPathList: public wxStringList
148 {
149 DECLARE_DYNAMIC_CLASS(wxPathList)
150
151 public:
152 void AddEnvList(const wxString& envVariable); // Adds all paths in environment variable
153 void Add(const wxString& path);
154 wxString FindValidPath(const wxString& filename); // Find the first full path
155 // for which the file exists
156 wxString FindAbsoluteValidPath(const wxString& filename); // Find the first full path
157 // for which the file exists; ensure it's an absolute
158 // path that gets returned.
159 void EnsureFileAccessible(const wxString& path); // Given full path and filename,
160 // add path to list
161 bool Member(const wxString& path);
162 };
163
164 #endif
165 // __FILEFNH__
166