2000-12-27 19:00:32 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-12-30 14:36:10 -05:00
|
|
|
// Name: wx/filename.h
|
|
|
|
// Purpose: wxFileName - encapsulates a file path
|
2000-12-30 19:23:09 -05:00
|
|
|
// Author: Robert Roebling, Vadim Zeitlin
|
2000-12-27 19:00:32 -05:00
|
|
|
// Modified by:
|
|
|
|
// Created: 28.12.00
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000 Robert Roebling
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2000-12-27 19:00:32 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_FILENAME_H_
|
|
|
|
#define _WX_FILENAME_H_
|
|
|
|
|
2000-12-30 20:15:33 -05:00
|
|
|
/*
|
|
|
|
TODO:
|
|
|
|
|
|
|
|
1. support for drives under Windows
|
|
|
|
2. more file operations:
|
|
|
|
a) chmod()
|
|
|
|
b) [acm]time() - get and set
|
2006-10-05 13:28:31 -04:00
|
|
|
c) rename()?
|
2000-12-30 20:15:33 -05:00
|
|
|
3. SameFileAs() function to compare inodes under Unix
|
|
|
|
*/
|
|
|
|
|
2005-09-25 16:49:40 -04:00
|
|
|
#include "wx/arrstr.h"
|
2000-12-29 12:39:00 -05:00
|
|
|
#include "wx/filefn.h"
|
2001-04-09 13:16:09 -04:00
|
|
|
#include "wx/datetime.h"
|
2006-08-18 16:56:34 -04:00
|
|
|
#include "wx/intl.h"
|
2007-07-16 16:33:27 -04:00
|
|
|
#include "wx/longlong.h"
|
2008-09-27 06:28:43 -04:00
|
|
|
#include "wx/file.h"
|
2000-12-27 19:00:32 -05:00
|
|
|
|
2005-02-24 13:01:42 -05:00
|
|
|
#if wxUSE_FILE
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxFile;
|
2005-02-24 13:01:42 -05:00
|
|
|
#endif
|
2001-12-18 12:47:27 -05:00
|
|
|
|
2006-10-23 09:10:12 -04:00
|
|
|
#if wxUSE_FFILE
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxFFile;
|
2006-10-23 09:10:12 -04:00
|
|
|
#endif
|
|
|
|
|
2008-09-13 21:18:05 -04:00
|
|
|
// this symbol is defined for the platforms where file systems use volumes in
|
|
|
|
// paths
|
|
|
|
#if defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
|
|
|
|
#define wxHAS_FILESYSTEM_VOLUMES
|
|
|
|
#endif
|
|
|
|
|
2000-12-30 14:36:10 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// the various values for the path format: this mainly affects the path
|
|
|
|
// separator but also whether or not the path has the drive part (as under
|
|
|
|
// Windows)
|
2000-12-27 19:00:32 -05:00
|
|
|
enum wxPathFormat
|
|
|
|
{
|
2000-12-30 19:23:09 -05:00
|
|
|
wxPATH_NATIVE = 0, // the path format for the current platform
|
2000-12-30 14:36:10 -05:00
|
|
|
wxPATH_UNIX,
|
2003-07-19 13:06:29 -04:00
|
|
|
wxPATH_BEOS = wxPATH_UNIX,
|
2000-12-30 14:36:10 -05:00
|
|
|
wxPATH_MAC,
|
|
|
|
wxPATH_DOS,
|
2003-07-19 13:06:29 -04:00
|
|
|
wxPATH_WIN = wxPATH_DOS,
|
|
|
|
wxPATH_OS2 = wxPATH_DOS,
|
2001-11-23 08:45:25 -05:00
|
|
|
wxPATH_VMS,
|
2000-12-29 12:39:00 -05:00
|
|
|
|
2003-07-19 13:06:29 -04:00
|
|
|
wxPATH_MAX // Not a valid value for specifying path format
|
2000-12-30 14:36:10 -05:00
|
|
|
};
|
2000-12-29 12:39:00 -05:00
|
|
|
|
2010-04-06 10:53:04 -04:00
|
|
|
// different convention that may be used with GetHumanReadableSize()
|
|
|
|
enum wxSizeConvention
|
|
|
|
{
|
|
|
|
wxSIZE_CONV_TRADIONAL, // 1024 bytes = 1 KB
|
|
|
|
wxSIZE_CONV_IEC, // 1024 bytes = 1 KiB
|
|
|
|
wxSIZE_CONV_SI // 1000 bytes = 1 KB
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-12-30 14:36:10 -05:00
|
|
|
// the kind of normalization to do with the file name: these values can be
|
|
|
|
// or'd together to perform several operations at once
|
|
|
|
enum wxPathNormalize
|
|
|
|
{
|
|
|
|
wxPATH_NORM_ENV_VARS = 0x0001, // replace env vars with their values
|
2009-08-01 21:03:00 -04:00
|
|
|
wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and .
|
2000-12-30 14:36:10 -05:00
|
|
|
wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user
|
2000-12-30 19:23:09 -05:00
|
|
|
wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower
|
|
|
|
wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute
|
2001-03-21 07:34:56 -05:00
|
|
|
wxPATH_NORM_LONG = 0x0020, // make the path the long form
|
2003-12-20 08:59:13 -05:00
|
|
|
wxPATH_NORM_SHORTCUT = 0x0040, // resolve the shortcut, if it is a shortcut
|
|
|
|
wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE
|
2000-12-27 19:00:32 -05:00
|
|
|
};
|
|
|
|
|
2002-04-08 12:15:43 -04:00
|
|
|
// what exactly should GetPath() return?
|
|
|
|
enum
|
|
|
|
{
|
2008-09-13 21:18:05 -04:00
|
|
|
wxPATH_NO_SEPARATOR = 0x0000, // for symmetry with wxPATH_GET_SEPARATOR
|
2002-04-08 12:15:43 -04:00
|
|
|
wxPATH_GET_VOLUME = 0x0001, // include the volume if applicable
|
|
|
|
wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator
|
|
|
|
};
|
|
|
|
|
2009-01-25 07:37:16 -05:00
|
|
|
// Mkdir flags
|
2002-04-08 12:28:50 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxPATH_MKDIR_FULL = 0x0001 // create directories recursively
|
|
|
|
};
|
|
|
|
|
2009-01-25 07:37:16 -05:00
|
|
|
// Rmdir flags
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxPATH_RMDIR_FULL = 0x0001, // delete with subdirectories if empty
|
|
|
|
wxPATH_RMDIR_RECURSIVE = 0x0002 // delete all recursively (dangerous!)
|
|
|
|
};
|
|
|
|
|
2007-07-10 19:19:17 -04:00
|
|
|
#if wxUSE_LONGLONG
|
2006-08-18 16:56:34 -04:00
|
|
|
// error code of wxFileName::GetSize()
|
2007-10-20 10:34:43 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_BASE(const wxULongLong) wxInvalidSize;
|
2007-07-10 19:19:17 -04:00
|
|
|
#endif // wxUSE_LONGLONG
|
2006-08-18 16:56:34 -04:00
|
|
|
|
|
|
|
|
2006-10-05 13:28:31 -04:00
|
|
|
|
2000-12-30 14:36:10 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFileName: encapsulates a file path
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-07-01 21:59:24 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxFileName
|
2000-12-27 19:00:32 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructors and assignment
|
2000-12-30 19:23:09 -05:00
|
|
|
|
|
|
|
// the usual stuff
|
2002-08-20 09:28:51 -04:00
|
|
|
wxFileName() { Clear(); }
|
2003-07-17 19:39:28 -04:00
|
|
|
wxFileName(const wxFileName& filepath) { Assign(filepath); }
|
2000-12-30 19:23:09 -05:00
|
|
|
|
|
|
|
// from a full filename: if it terminates with a '/', a directory path
|
|
|
|
// is contructed (the name will be empty), otherwise a file name and
|
|
|
|
// extension are extracted from it
|
|
|
|
wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE )
|
|
|
|
{ Assign( fullpath, format ); }
|
|
|
|
|
|
|
|
// from a directory name and a file name
|
|
|
|
wxFileName(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE)
|
|
|
|
{ Assign(path, name, format); }
|
|
|
|
|
2001-12-03 20:14:09 -05:00
|
|
|
// from a volume, directory name, file base name and extension
|
|
|
|
wxFileName(const wxString& volume,
|
|
|
|
const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE)
|
|
|
|
{ Assign(volume, path, name, ext, format); }
|
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// from a directory name, file base name and extension
|
|
|
|
wxFileName(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE)
|
|
|
|
{ Assign(path, name, ext, format); }
|
|
|
|
|
|
|
|
// the same for delayed initialization
|
|
|
|
|
|
|
|
void Assign(const wxFileName& filepath);
|
2001-11-30 16:55:13 -05:00
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
void Assign(const wxString& fullpath,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 16:55:13 -05:00
|
|
|
|
|
|
|
void Assign(const wxString& volume,
|
|
|
|
const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
2005-02-27 19:18:37 -05:00
|
|
|
bool hasExt,
|
2001-11-30 16:55:13 -05:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2005-02-27 19:18:37 -05:00
|
|
|
void Assign(const wxString& volume,
|
|
|
|
const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE)
|
|
|
|
{ Assign(volume, path, name, ext, !ext.empty(), format); }
|
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
void Assign(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 16:55:13 -05:00
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
void Assign(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
2004-11-07 15:11:42 -05:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 16:55:13 -05:00
|
|
|
|
2001-11-30 21:28:51 -05:00
|
|
|
void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE);
|
2000-12-30 19:23:09 -05:00
|
|
|
|
2001-05-14 12:13:12 -04:00
|
|
|
// assorted assignment operators
|
|
|
|
|
|
|
|
wxFileName& operator=(const wxFileName& filename)
|
2008-11-16 13:03:08 -05:00
|
|
|
{ if (this != &filename) Assign(filename); return *this; }
|
2001-05-14 12:13:12 -04:00
|
|
|
|
|
|
|
wxFileName& operator=(const wxString& filename)
|
|
|
|
{ Assign(filename); return *this; }
|
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// reset all components to default, uninitialized state
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// static pseudo constructors
|
2003-07-17 19:39:28 -04:00
|
|
|
static wxFileName FileName(const wxString& file,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
static wxFileName DirName(const wxString& dir,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2000-12-30 19:23:09 -05:00
|
|
|
|
2001-10-29 21:41:30 -05:00
|
|
|
// file tests
|
2000-12-30 19:23:09 -05:00
|
|
|
|
|
|
|
// is the filename valid at all?
|
2004-02-16 13:30:18 -05:00
|
|
|
bool IsOk() const
|
2004-09-14 08:08:28 -04:00
|
|
|
{
|
2004-02-16 13:30:18 -05:00
|
|
|
// we're fine if we have the path or the name or if we're a root dir
|
2005-03-17 12:46:32 -05:00
|
|
|
return m_dirs.size() != 0 || !m_name.empty() || !m_relative ||
|
2005-02-27 19:18:37 -05:00
|
|
|
!m_ext.empty() || m_hasExt;
|
2004-02-16 13:30:18 -05:00
|
|
|
}
|
2000-12-30 19:23:09 -05:00
|
|
|
|
|
|
|
// does the file with this name exists?
|
2003-01-25 07:01:57 -05:00
|
|
|
bool FileExists() const;
|
2000-12-29 19:28:00 -05:00
|
|
|
static bool FileExists( const wxString &file );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// does the directory with this name exists?
|
2003-01-25 07:01:57 -05:00
|
|
|
bool DirExists() const;
|
2000-12-29 19:28:00 -05:00
|
|
|
static bool DirExists( const wxString &dir );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2006-10-05 13:28:31 -04:00
|
|
|
// checks on most common flags for files/directories;
|
|
|
|
// more platform-specific features (like e.g. Unix permissions) are not
|
|
|
|
// available in wxFileName
|
|
|
|
|
|
|
|
bool IsDirWritable() const { return wxIsWritable(GetPath()); }
|
|
|
|
static bool IsDirWritable(const wxString &path) { return wxDirExists(path) && wxIsWritable(path); }
|
|
|
|
|
|
|
|
bool IsDirReadable() const { return wxIsReadable(GetPath()); }
|
|
|
|
static bool IsDirReadable(const wxString &path) { return wxDirExists(path) && wxIsReadable(path); }
|
|
|
|
|
|
|
|
// NOTE: IsDirExecutable() is not present because the meaning of "executable"
|
|
|
|
// directory is very platform-dependent and also not so useful
|
|
|
|
|
|
|
|
bool IsFileWritable() const { return wxIsWritable(GetFullPath()); }
|
|
|
|
static bool IsFileWritable(const wxString &path) { return wxFileExists(path) && wxIsWritable(path); }
|
|
|
|
|
|
|
|
bool IsFileReadable() const { return wxIsReadable(GetFullPath()); }
|
|
|
|
static bool IsFileReadable(const wxString &path) { return wxFileExists(path) && wxIsReadable(path); }
|
|
|
|
|
|
|
|
bool IsFileExecutable() const { return wxIsExecutable(GetFullPath()); }
|
|
|
|
static bool IsFileExecutable(const wxString &path) { return wxFileExists(path) && wxIsExecutable(path); }
|
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
|
2001-10-29 21:41:30 -05:00
|
|
|
// time functions
|
2003-02-05 19:53:46 -05:00
|
|
|
#if wxUSE_DATETIME
|
2002-03-27 18:17:41 -05:00
|
|
|
// set the file last access/mod and creation times
|
2001-10-29 21:41:30 -05:00
|
|
|
// (any of the pointers may be NULL)
|
2002-03-27 18:17:41 -05:00
|
|
|
bool SetTimes(const wxDateTime *dtAccess,
|
|
|
|
const wxDateTime *dtMod,
|
2009-06-12 11:28:45 -04:00
|
|
|
const wxDateTime *dtCreate) const;
|
2001-10-29 21:41:30 -05:00
|
|
|
|
|
|
|
// set the access and modification times to the current moment
|
2009-06-12 11:28:45 -04:00
|
|
|
bool Touch() const;
|
2001-10-29 21:41:30 -05:00
|
|
|
|
2002-03-27 18:17:41 -05:00
|
|
|
// return the last access, last modification and create times
|
2001-10-29 21:41:30 -05:00
|
|
|
// (any of the pointers may be NULL)
|
|
|
|
bool GetTimes(wxDateTime *dtAccess,
|
|
|
|
wxDateTime *dtMod,
|
2002-03-27 18:17:41 -05:00
|
|
|
wxDateTime *dtCreate) const;
|
2001-10-29 21:41:30 -05:00
|
|
|
|
|
|
|
// convenience wrapper: get just the last mod time of the file
|
|
|
|
wxDateTime GetModificationTime() const
|
|
|
|
{
|
|
|
|
wxDateTime dtMod;
|
|
|
|
(void)GetTimes(NULL, &dtMod, NULL);
|
|
|
|
return dtMod;
|
|
|
|
}
|
2003-02-05 19:53:46 -05:00
|
|
|
#endif // wxUSE_DATETIME
|
2001-10-29 21:41:30 -05:00
|
|
|
|
2008-07-29 16:22:57 -04:00
|
|
|
#if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON
|
2002-01-13 12:38:55 -05:00
|
|
|
bool MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) ;
|
2009-06-12 11:28:45 -04:00
|
|
|
bool MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) const;
|
2002-01-13 12:38:55 -05:00
|
|
|
// gets the 'common' type and creator for a certain extension
|
|
|
|
static bool MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator ) ;
|
|
|
|
// registers application defined extensions and their default type and creator
|
|
|
|
static void MacRegisterDefaultTypeAndCreator( const wxString& ext , wxUint32 type , wxUint32 creator ) ;
|
|
|
|
// looks up the appropriate type and creator from the registration and then sets
|
|
|
|
bool MacSetDefaultTypeAndCreator() ;
|
|
|
|
#endif
|
2002-08-20 09:28:51 -04:00
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// various file/dir operations
|
|
|
|
|
|
|
|
// retrieve the value of the current working directory
|
2001-11-30 22:16:19 -05:00
|
|
|
void AssignCwd(const wxString& volume = wxEmptyString);
|
|
|
|
static wxString GetCwd(const wxString& volume = wxEmptyString);
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// change the current working directory
|
2009-06-12 11:28:45 -04:00
|
|
|
bool SetCwd() const;
|
2000-12-29 19:28:00 -05:00
|
|
|
static bool SetCwd( const wxString &cwd );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// get the value of user home (Unix only mainly)
|
2000-12-29 19:28:00 -05:00
|
|
|
void AssignHomeDir();
|
|
|
|
static wxString GetHomeDir();
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2006-10-23 13:47:02 -04:00
|
|
|
// get the system temporary directory
|
|
|
|
static wxString GetTempDir();
|
|
|
|
|
2006-10-23 09:10:12 -04:00
|
|
|
#if wxUSE_FILE || wxUSE_FFILE
|
|
|
|
// get a temp file name starting with the specified prefix
|
|
|
|
void AssignTempFileName(const wxString& prefix);
|
|
|
|
static wxString CreateTempFileName(const wxString& prefix);
|
|
|
|
#endif // wxUSE_FILE
|
|
|
|
|
2005-02-24 13:01:42 -05:00
|
|
|
#if wxUSE_FILE
|
2001-12-18 12:47:27 -05:00
|
|
|
// get a temp file name starting with the specified prefix and open the
|
|
|
|
// file passed to us using this name for writing (atomically if
|
|
|
|
// possible)
|
2006-10-23 09:10:12 -04:00
|
|
|
void AssignTempFileName(const wxString& prefix, wxFile *fileTemp);
|
2001-12-18 12:47:27 -05:00
|
|
|
static wxString CreateTempFileName(const wxString& prefix,
|
2006-10-23 09:10:12 -04:00
|
|
|
wxFile *fileTemp);
|
2005-02-24 13:01:42 -05:00
|
|
|
#endif // wxUSE_FILE
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2006-10-23 09:10:12 -04:00
|
|
|
#if wxUSE_FFILE
|
|
|
|
// get a temp file name starting with the specified prefix and open the
|
|
|
|
// file passed to us using this name for writing (atomically if
|
|
|
|
// possible)
|
|
|
|
void AssignTempFileName(const wxString& prefix, wxFFile *fileTemp);
|
|
|
|
static wxString CreateTempFileName(const wxString& prefix,
|
|
|
|
wxFFile *fileTemp);
|
|
|
|
#endif // wxUSE_FFILE
|
|
|
|
|
2001-03-26 08:31:12 -05:00
|
|
|
// directory creation and removal.
|
2009-06-11 12:11:07 -04:00
|
|
|
bool Mkdir(int perm = wxS_DIR_DEFAULT, int flags = 0) const;
|
2009-01-25 07:37:16 -05:00
|
|
|
static bool Mkdir(const wxString &dir, int perm = wxS_DIR_DEFAULT,
|
|
|
|
int flags = 0);
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2009-06-11 12:11:07 -04:00
|
|
|
bool Rmdir(int flags = 0) const;
|
2009-01-25 07:37:16 -05:00
|
|
|
static bool Rmdir(const wxString &dir, int flags = 0);
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// operations on the path
|
|
|
|
|
|
|
|
// normalize the path: with the default flags value, the path will be
|
|
|
|
// made absolute, without any ".." and "." and all environment
|
|
|
|
// variables will be expanded in it
|
|
|
|
//
|
|
|
|
// this may be done using another (than current) value of cwd
|
2002-02-02 18:14:45 -05:00
|
|
|
bool Normalize(int flags = wxPATH_NORM_ALL,
|
2000-12-30 19:23:09 -05:00
|
|
|
const wxString& cwd = wxEmptyString,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2001-12-04 10:13:56 -05:00
|
|
|
// get a path path relative to the given base directory, i.e. opposite
|
|
|
|
// of Normalize
|
|
|
|
//
|
|
|
|
// pass an empty string to get a path relative to the working directory
|
|
|
|
//
|
2003-07-19 13:06:29 -04:00
|
|
|
// returns true if the file name was modified, false if we failed to do
|
2001-12-04 10:13:56 -05:00
|
|
|
// anything with it (happens when the file is on a different volume,
|
|
|
|
// for example)
|
2003-07-10 04:36:14 -04:00
|
|
|
bool MakeRelativeTo(const wxString& pathBase = wxEmptyString,
|
2001-12-04 10:13:56 -05:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2003-01-17 19:01:18 -05:00
|
|
|
// make the path absolute
|
|
|
|
//
|
|
|
|
// this may be done using another (than current) value of cwd
|
|
|
|
bool MakeAbsolute(const wxString& cwd = wxEmptyString,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE)
|
|
|
|
{ return Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
|
|
|
|
wxPATH_NORM_TILDE, cwd, format); }
|
2001-12-04 10:13:56 -05:00
|
|
|
|
2004-01-26 07:44:14 -05:00
|
|
|
#if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE
|
2003-12-20 08:59:13 -05:00
|
|
|
// if the path is a shortcut, return the target and optionally,
|
|
|
|
// the arguments
|
2004-01-26 07:44:14 -05:00
|
|
|
bool GetShortcutTarget(const wxString& shortcutPath,
|
|
|
|
wxString& targetFilename,
|
2009-06-12 11:28:45 -04:00
|
|
|
wxString* arguments = NULL) const;
|
2003-12-20 08:59:13 -05:00
|
|
|
#endif
|
|
|
|
|
2009-01-06 19:38:46 -05:00
|
|
|
#ifndef __WXWINCE__
|
|
|
|
// if the path contains the value of the environment variable named envname
|
|
|
|
// then this function replaces it with the string obtained from
|
|
|
|
// wxString::Format(replacementFmtString, value_of_envname_variable)
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
// wxFileName fn("/usr/openwin/lib/someFile");
|
|
|
|
// fn.ReplaceEnvVariable("OPENWINHOME");
|
|
|
|
// // now fn.GetFullPath() == "$OPENWINHOME/lib/someFile"
|
|
|
|
bool ReplaceEnvVariable(const wxString& envname,
|
|
|
|
const wxString& replacementFmtString = "$%s",
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// replaces, if present in the path, the home directory for the given user
|
|
|
|
// (see wxGetHomeDir) with a tilde
|
|
|
|
bool ReplaceHomeDir(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Comparison
|
2000-12-30 19:23:09 -05:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
// compares with the rules of the given platforms format
|
|
|
|
bool SameAs(const wxFileName& filepath,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE) const;
|
|
|
|
|
|
|
|
// compare with another filename object
|
|
|
|
bool operator==(const wxFileName& filename) const
|
|
|
|
{ return SameAs(filename); }
|
|
|
|
bool operator!=(const wxFileName& filename) const
|
|
|
|
{ return !SameAs(filename); }
|
|
|
|
|
|
|
|
// compare with a filename string interpreted as a native file name
|
|
|
|
bool operator==(const wxString& filename) const
|
|
|
|
{ return SameAs(wxFileName(filename)); }
|
|
|
|
bool operator!=(const wxString& filename) const
|
|
|
|
{ return !SameAs(wxFileName(filename)); }
|
2000-12-30 19:23:09 -05:00
|
|
|
|
2001-11-30 16:55:13 -05:00
|
|
|
// are the file names of this type cases sensitive?
|
2000-12-30 19:23:09 -05:00
|
|
|
static bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE );
|
2001-11-30 16:55:13 -05:00
|
|
|
|
|
|
|
// is this filename absolute?
|
2002-03-28 06:44:30 -05:00
|
|
|
bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE) const;
|
2000-12-30 19:23:09 -05:00
|
|
|
|
2001-11-30 16:55:13 -05:00
|
|
|
// is this filename relative?
|
2002-03-28 06:44:30 -05:00
|
|
|
bool IsRelative(wxPathFormat format = wxPATH_NATIVE) const
|
|
|
|
{ return !IsAbsolute(format); }
|
2001-11-30 16:55:13 -05:00
|
|
|
|
2003-07-19 13:06:29 -04:00
|
|
|
// Returns the characters that aren't allowed in filenames
|
|
|
|
// on the specified platform.
|
|
|
|
static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2001-11-30 16:55:13 -05:00
|
|
|
// Information about path format
|
|
|
|
|
2002-03-28 06:44:30 -05:00
|
|
|
// get the string separating the volume from the path for this format,
|
|
|
|
// return an empty string if this format doesn't support the notion of
|
|
|
|
// volumes at all
|
2001-11-30 16:55:13 -05:00
|
|
|
static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// get the string of path separators for this format
|
|
|
|
static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2004-07-25 09:59:47 -04:00
|
|
|
// get the string of path terminators, i.e. characters which terminate the
|
|
|
|
// path
|
|
|
|
static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2002-03-28 06:44:30 -05:00
|
|
|
// get the canonical path separator for this format
|
2007-03-17 06:26:10 -04:00
|
|
|
static wxUniChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE)
|
2002-03-28 06:44:30 -05:00
|
|
|
{ return GetPathSeparators(format)[0u]; }
|
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// is the char a path separator for this format?
|
|
|
|
static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2009-12-05 12:31:00 -05:00
|
|
|
// is this is a DOS path which beings with a windows unique volume name
|
|
|
|
// ('\\?\Volume{guid}\')?
|
|
|
|
static bool IsMSWUniqueVolumeNamePath(const wxString& path,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Dir accessors
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 15:52:35 -04:00
|
|
|
size_t GetDirCount() const { return m_dirs.size(); }
|
2005-02-12 19:55:27 -05:00
|
|
|
void AppendDir(const wxString& dir);
|
|
|
|
void PrependDir(const wxString& dir);
|
|
|
|
void InsertDir(size_t before, const wxString& dir);
|
|
|
|
void RemoveDir(size_t pos);
|
|
|
|
void RemoveLastDir() { RemoveDir(GetDirCount() - 1); }
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Other accessors
|
2005-03-04 12:31:18 -05:00
|
|
|
void SetExt( const wxString &ext ) { m_ext = ext; m_hasExt = !m_ext.empty(); }
|
|
|
|
void ClearExt() { m_ext = wxEmptyString; m_hasExt = false; }
|
|
|
|
void SetEmptyExt() { m_ext = wxT(""); m_hasExt = true; }
|
2000-12-27 19:00:32 -05:00
|
|
|
wxString GetExt() const { return m_ext; }
|
2005-03-03 14:45:24 -05:00
|
|
|
bool HasExt() const { return m_hasExt; }
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
void SetName( const wxString &name ) { m_name = name; }
|
|
|
|
wxString GetName() const { return m_name; }
|
2001-11-30 16:55:13 -05:00
|
|
|
bool HasName() const { return !m_name.empty(); }
|
|
|
|
|
|
|
|
void SetVolume( const wxString &volume ) { m_volume = volume; }
|
|
|
|
wxString GetVolume() const { return m_volume; }
|
|
|
|
bool HasVolume() const { return !m_volume.empty(); }
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-31 10:23:43 -05:00
|
|
|
// full name is the file name + extension (but without the path)
|
|
|
|
void SetFullName(const wxString& fullname);
|
2000-12-30 19:23:09 -05:00
|
|
|
wxString GetFullName() const;
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2001-11-30 16:55:13 -05:00
|
|
|
const wxArrayString& GetDirs() const { return m_dirs; }
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2002-04-08 12:15:43 -04:00
|
|
|
// flags are combination of wxPATH_GET_XXX flags
|
2003-07-27 18:53:23 -04:00
|
|
|
wxString GetPath(int flags = wxPATH_GET_VOLUME,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE) const;
|
2002-04-08 12:15:43 -04:00
|
|
|
|
2001-12-23 10:52:29 -05:00
|
|
|
// Replace current path with this one
|
|
|
|
void SetPath( const wxString &path, wxPathFormat format = wxPATH_NATIVE );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Construct full path with name and ext
|
|
|
|
wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const;
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2001-03-21 07:34:56 -05:00
|
|
|
// Return the short form of the path (returns identity on non-Windows platforms)
|
|
|
|
wxString GetShortPath() const;
|
|
|
|
|
|
|
|
// Return the long form of the path (returns identity on non-Windows platforms)
|
|
|
|
wxString GetLongPath() const;
|
|
|
|
|
2002-04-05 06:14:09 -05:00
|
|
|
// Is this a file or directory (not necessarily an existing one)
|
|
|
|
bool IsDir() const { return m_name.empty() && m_ext.empty(); }
|
|
|
|
|
2000-12-30 20:15:33 -05:00
|
|
|
// various helpers
|
|
|
|
|
|
|
|
// get the canonical path format for this platform
|
2000-12-27 19:00:32 -05:00
|
|
|
static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2001-11-30 16:55:13 -05:00
|
|
|
// split a fullpath into the volume, path, (base) name and extension
|
|
|
|
// (all of the pointers can be NULL)
|
2000-12-30 20:15:33 -05:00
|
|
|
static void SplitPath(const wxString& fullpath,
|
2001-11-30 16:55:13 -05:00
|
|
|
wxString *volume,
|
2000-12-30 20:15:33 -05:00
|
|
|
wxString *path,
|
|
|
|
wxString *name,
|
|
|
|
wxString *ext,
|
2005-02-27 19:18:37 -05:00
|
|
|
bool *hasExt = NULL,
|
2000-12-30 20:15:33 -05:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2005-02-27 19:18:37 -05:00
|
|
|
static void SplitPath(const wxString& fullpath,
|
|
|
|
wxString *volume,
|
|
|
|
wxString *path,
|
|
|
|
wxString *name,
|
|
|
|
wxString *ext,
|
2005-02-28 12:23:19 -05:00
|
|
|
wxPathFormat format)
|
2005-02-27 19:18:37 -05:00
|
|
|
{
|
|
|
|
SplitPath(fullpath, volume, path, name, ext, NULL, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
// compatibility version: volume is part of path
|
2001-11-30 16:55:13 -05:00
|
|
|
static void SplitPath(const wxString& fullpath,
|
|
|
|
wxString *path,
|
|
|
|
wxString *name,
|
|
|
|
wxString *ext,
|
2001-11-30 22:16:19 -05:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 16:55:13 -05:00
|
|
|
|
2004-07-25 09:59:47 -04:00
|
|
|
// split a path into volume and pure path part
|
|
|
|
static void SplitVolume(const wxString& fullpathWithVolume,
|
|
|
|
wxString *volume,
|
|
|
|
wxString *path,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2002-04-08 12:15:43 -04:00
|
|
|
|
2009-03-26 12:02:09 -04:00
|
|
|
// strip the file extension: "foo.bar" => "foo" (but ".baz" => ".baz")
|
2009-03-26 11:55:01 -04:00
|
|
|
static wxString StripExtension(const wxString& fullpath);
|
|
|
|
|
2008-09-13 21:18:05 -04:00
|
|
|
#ifdef wxHAS_FILESYSTEM_VOLUMES
|
|
|
|
// return the string representing a file system volume, or drive
|
|
|
|
static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
|
|
|
|
#endif // wxHAS_FILESYSTEM_VOLUMES
|
|
|
|
|
|
|
|
// File size
|
2006-08-18 16:56:34 -04:00
|
|
|
|
2007-07-10 19:19:17 -04:00
|
|
|
#if wxUSE_LONGLONG
|
2006-08-18 16:56:34 -04:00
|
|
|
// returns the size of the given filename
|
|
|
|
wxULongLong GetSize() const;
|
|
|
|
static wxULongLong GetSize(const wxString &file);
|
|
|
|
|
|
|
|
// returns the size in a human readable form
|
2010-04-06 10:53:04 -04:00
|
|
|
wxString
|
|
|
|
GetHumanReadableSize(const wxString& nullsize = _("Not available"),
|
|
|
|
int precision = 1,
|
|
|
|
wxSizeConvention conv = wxSIZE_CONV_TRADIONAL) const;
|
|
|
|
static wxString
|
|
|
|
GetHumanReadableSize(const wxULongLong& sz,
|
|
|
|
const wxString& nullsize = _("Not available"),
|
|
|
|
int precision = 1,
|
|
|
|
wxSizeConvention conv = wxSIZE_CONV_TRADIONAL);
|
2007-07-10 19:19:17 -04:00
|
|
|
#endif // wxUSE_LONGLONG
|
2006-08-18 16:56:34 -04:00
|
|
|
|
|
|
|
|
2002-04-08 12:15:43 -04:00
|
|
|
// deprecated methods, don't use any more
|
|
|
|
// --------------------------------------
|
|
|
|
|
2003-04-19 14:15:17 -04:00
|
|
|
#ifndef __DIGITALMARS__
|
2002-04-08 12:15:43 -04:00
|
|
|
wxString GetPath( bool withSep, wxPathFormat format = wxPATH_NATIVE ) const
|
|
|
|
{ return GetPath(withSep ? wxPATH_GET_SEPARATOR : 0, format); }
|
2003-04-19 14:15:17 -04:00
|
|
|
#endif
|
2002-04-08 12:15:43 -04:00
|
|
|
wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const
|
2006-05-03 09:11:18 -04:00
|
|
|
{ return GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format); }
|
2002-04-08 12:15:43 -04:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
private:
|
2003-10-08 19:15:16 -04:00
|
|
|
// check whether this dir is valid for Append/Prepend/InsertDir()
|
|
|
|
static bool IsValidDirComponent(const wxString& dir);
|
|
|
|
|
2001-11-30 16:55:13 -05:00
|
|
|
// the drive/volume/device specification (always empty for Unix)
|
|
|
|
wxString m_volume;
|
|
|
|
|
2000-12-30 19:23:09 -05:00
|
|
|
// the path components of the file
|
2000-12-27 19:00:32 -05:00
|
|
|
wxArrayString m_dirs;
|
2000-12-30 19:23:09 -05:00
|
|
|
|
|
|
|
// the file name and extension (empty for directories)
|
|
|
|
wxString m_name,
|
|
|
|
m_ext;
|
2002-03-28 06:44:30 -05:00
|
|
|
|
|
|
|
// when m_dirs is empty it may mean either that we have no path at all or
|
|
|
|
// that our path is '/', i.e. the root directory
|
|
|
|
//
|
|
|
|
// we use m_relative to distinguish between these two cases, it will be
|
2003-07-19 13:06:29 -04:00
|
|
|
// true in the former and false in the latter
|
2002-03-28 06:44:30 -05:00
|
|
|
//
|
2003-07-19 13:06:29 -04:00
|
|
|
// NB: the path is not absolute just because m_relative is false, it still
|
2002-03-28 06:44:30 -05:00
|
|
|
// needs the drive (i.e. volume) in some formats (Windows)
|
2001-12-16 07:07:44 -05:00
|
|
|
bool m_relative;
|
2005-02-27 19:18:37 -05:00
|
|
|
|
|
|
|
// when m_ext is empty, it may be because we don't have any extension or
|
|
|
|
// because we have an empty extension
|
|
|
|
//
|
|
|
|
// the difference is important as file with name "foo" and without
|
|
|
|
// extension has full name "foo" while with empty extension it is "foo."
|
|
|
|
bool m_hasExt;
|
2000-12-27 19:00:32 -05:00
|
|
|
};
|
|
|
|
|
2000-12-30 14:36:10 -05:00
|
|
|
#endif // _WX_FILENAME_H_
|
2000-12-27 19:00:32 -05:00
|
|
|
|