1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: filefn.h
|
|
|
|
// Purpose: File- and directory-related functions
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Julian Smart
|
1998-07-14 18:15:29 -04:00
|
|
|
// Licence: wxWindows license
|
1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _FILEFN_H_
|
|
|
|
#define _FILEFN_H_
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "filefn.h"
|
|
|
|
#endif
|
|
|
|
|
1998-07-15 14:40:37 -04:00
|
|
|
#include <wx/list.h>
|
|
|
|
|
1998-07-14 18:15:29 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-14 18:15:29 -04:00
|
|
|
// define off_t
|
1999-01-01 11:22:21 -05:00
|
|
|
#ifndef __WXMAC__
|
1998-07-14 18:15:29 -04:00
|
|
|
#include <sys/types.h>
|
1999-01-01 11:22:21 -05:00
|
|
|
#else
|
|
|
|
typedef long off_t;
|
|
|
|
#endif
|
1998-07-14 18:15:29 -04:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define off_t _off_t
|
|
|
|
#endif
|
|
|
|
|
1998-12-28 07:35:49 -05:00
|
|
|
#if defined(__BORLANDC__) && defined(__WIN16__)
|
|
|
|
typedef long off_t;
|
|
|
|
#endif
|
|
|
|
|
1999-01-07 03:43:47 -05:00
|
|
|
#if defined(__SC__)
|
|
|
|
typedef long off_t;
|
|
|
|
#endif
|
|
|
|
|
1998-07-24 13:13:47 -04:00
|
|
|
const off_t wxInvalidOffset = (off_t)-1;
|
|
|
|
|
1998-07-14 18:15:29 -04:00
|
|
|
typedef enum {
|
|
|
|
wxFromStart,
|
|
|
|
wxFromCurrent,
|
|
|
|
wxFromEnd
|
|
|
|
} wxSeekMode;
|
|
|
|
|
1998-12-28 13:53:03 -05:00
|
|
|
WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
|
|
|
|
|
1998-07-14 18:15:29 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// functions
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxFileExists(const wxString& filename);
|
1998-05-20 10:01:55 -04:00
|
|
|
#define FileExists wxFileExists
|
|
|
|
|
|
|
|
// does the path exist? (may have or not '/' or '\\' at the end)
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxPathExists(const char *pszPathName);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
#define wxDirExists wxPathExists
|
|
|
|
#define DirExists wxDirExists
|
|
|
|
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxIsAbsolutePath(const wxString& filename);
|
1998-05-20 10:01:55 -04:00
|
|
|
#define IsAbsolutePath wxIsAbsolutePath
|
|
|
|
|
|
|
|
// Get filename
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxFileNameFromPath(char *path);
|
|
|
|
WXDLLEXPORT wxString wxFileNameFromPath(const wxString& path);
|
1998-05-20 10:01:55 -04:00
|
|
|
#define FileNameFromPath wxFileNameFromPath
|
|
|
|
|
|
|
|
// Get directory
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxPathOnly(char *path);
|
|
|
|
WXDLLEXPORT wxString wxPathOnly(const wxString& path);
|
1998-05-20 10:01:55 -04:00
|
|
|
#define PathOnly wxPathOnly
|
|
|
|
|
|
|
|
// wxString version
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT wxString wxRealPath(const wxString& path);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT void wxDos2UnixFilename(char *s);
|
1998-05-20 10:01:55 -04:00
|
|
|
#define Dos2UnixFilename wxDos2UnixFilename
|
|
|
|
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT void wxUnix2DosFilename(char *s);
|
1998-05-20 10:01:55 -04:00
|
|
|
#define Unix2DosFilename wxUnix2DosFilename
|
|
|
|
|
1999-01-01 11:22:21 -05:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
WXDLLEXPORT void wxMacPathToFSSpec( const char *path , FSSpec *spec ) ;
|
|
|
|
WXDLLEXPORT void wxMac2UnixFilename(char *s);
|
|
|
|
WXDLLEXPORT void wxUnix2MacFilename(char *s);
|
|
|
|
#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
// Strip the extension, in situ
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT void wxStripExtension(char *buffer);
|
|
|
|
WXDLLEXPORT void wxStripExtension(wxString& buffer);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Get a temporary filename, opening and closing the file.
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxGetTempFileName(const wxString& prefix, char *buf = (char *) NULL);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Expand file name (~/ and ${OPENWINHOME}/ stuff)
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxExpandPath(char *dest, const char *path);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
|
|
|
|
// and make (if under the home tree) relative to home
|
|
|
|
// [caller must copy-- volatile]
|
1999-01-14 09:33:56 -05:00
|
|
|
WXDLLEXPORT char* wxContractPath(const wxString& filename,
|
|
|
|
const wxString& envname = "",
|
|
|
|
const wxString& user = "");
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Destructive removal of /./ and /../ stuff
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxRealPath(char *path);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Allocate a copy of the full absolute path
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxCopyAbsolutePath(const wxString& path);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Get first file name matching given wild card.
|
|
|
|
// Flags are reserved for future use.
|
|
|
|
#define wxFILE 1
|
|
|
|
#define wxDIR 2
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxFindFirstFile(const char *spec, int flags = wxFILE);
|
|
|
|
WXDLLEXPORT char* wxFindNextFile(void);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Does the pattern contain wildcards?
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxIsWild(const wxString& pattern);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Does the pattern match the text (usually a filename)?
|
|
|
|
// If dot_special is TRUE, doesn't match * against . (eliminating
|
|
|
|
// `hidden' dot files)
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Concatenate two files to form third
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Copy file1 to file2
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxCopyFile(const wxString& file1, const wxString& file2);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Remove file
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxRemoveFile(const wxString& file);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Rename file
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxRenameFile(const wxString& file1, const wxString& file2);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Get current working directory.
|
|
|
|
// If buf is NULL, allocates space using new, else
|
|
|
|
// copies into buf.
|
|
|
|
// IMPORTANT NOTE getcwd is know not to work under some releases
|
|
|
|
// of Win32s 1.3, according to MS release notes!
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT char* wxGetWorkingDirectory(char *buf = (char *) NULL, int sz = 1000);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Set working directory
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxSetWorkingDirectory(const wxString& d);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Make directory
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxMkdir(const wxString& dir);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Remove directory. Flags reserved for future use.
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxRmdir(const wxString& dir, int flags = 0);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// separators in file names
|
|
|
|
#define FILE_SEP_EXT '.'
|
|
|
|
#define FILE_SEP_DSK ':'
|
|
|
|
#define FILE_SEP_PATH_DOS '\\'
|
|
|
|
#define FILE_SEP_PATH_UNIX '/'
|
|
|
|
|
|
|
|
// separator in the path list (as in PATH environment variable)
|
|
|
|
// NB: these are strings and not characters on purpose!
|
|
|
|
#define PATH_SEP_DOS ";"
|
|
|
|
#define PATH_SEP_UNIX ":"
|
|
|
|
|
|
|
|
// platform independent versions
|
|
|
|
#ifdef __UNIX__
|
|
|
|
#define FILE_SEP_PATH FILE_SEP_PATH_UNIX
|
|
|
|
#define PATH_SEP PATH_SEP_UNIX
|
|
|
|
#else // Windows
|
|
|
|
#define FILE_SEP_PATH FILE_SEP_PATH_DOS
|
|
|
|
#define PATH_SEP PATH_SEP_DOS
|
|
|
|
#endif // Unix/Windows
|
|
|
|
|
1998-07-14 17:55:17 -04:00
|
|
|
// this is useful for wxString::IsSameAs(): to compare two file names use
|
|
|
|
// filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
|
|
|
|
#ifdef __UNIX__
|
|
|
|
#define wxARE_FILENAMES_CASE_SENSITIVE TRUE
|
|
|
|
#else // Windows
|
|
|
|
#define wxARE_FILENAMES_CASE_SENSITIVE FALSE
|
|
|
|
#endif // Unix/Windows
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// is the char a path separator?
|
|
|
|
inline bool wxIsPathSeparator(char c)
|
|
|
|
{ return c == FILE_SEP_PATH_DOS || c == FILE_SEP_PATH_UNIX; }
|
|
|
|
|
|
|
|
// does the string ends with path separator?
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxEndsWithPathSeparator(const char *pszFileName);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-14 17:55:17 -04:00
|
|
|
// split the full path into path (including drive for DOS), name and extension
|
|
|
|
// (understands both '/' and '\\')
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT void wxSplitPath(const char *pszFileName,
|
1998-07-14 17:55:17 -04:00
|
|
|
wxString *pstrPath,
|
|
|
|
wxString *pstrName,
|
|
|
|
wxString *pstrExt);
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// find a file in a list of directories, returns false if not found
|
1998-11-22 17:32:53 -05:00
|
|
|
WXDLLEXPORT bool wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-14 18:15:29 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// Path searching
|
1998-11-29 17:21:32 -05:00
|
|
|
class WXDLLEXPORT wxPathList : public wxStringList
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
1998-11-29 17:21:32 -05:00
|
|
|
public:
|
|
|
|
void AddEnvList(const wxString& envVariable); // Adds all paths in environment variable
|
|
|
|
void Add(const wxString& path);
|
|
|
|
wxString FindValidPath(const wxString& filename); // Find the first full path
|
|
|
|
// for which the file exists
|
|
|
|
wxString FindAbsoluteValidPath(const wxString& filename); // Find the first full path
|
|
|
|
// for which the file exists; ensure it's an absolute
|
|
|
|
// path that gets returned.
|
|
|
|
void EnsureFileAccessible(const wxString& path); // Given full path and filename,
|
|
|
|
// add path to list
|
|
|
|
bool Member(const wxString& path);
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxPathList)
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
1998-08-14 20:23:28 -04:00
|
|
|
// _WX_FILEFN_H_
|
1998-05-20 10:01:55 -04:00
|
|
|
|