2000-12-28 00:00:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-12-30 19:36:10 +00:00
|
|
|
// Name: wx/filename.h
|
|
|
|
// Purpose: wxFileName - encapsulates a file path
|
2000-12-31 00:23:09 +00:00
|
|
|
// Author: Robert Roebling, Vadim Zeitlin
|
2000-12-28 00:00:32 +00:00
|
|
|
// Modified by:
|
|
|
|
// Created: 28.12.00
|
|
|
|
// Copyright: (c) 2000 Robert Roebling
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
2000-12-28 00:00:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_FILENAME_H_
|
|
|
|
#define _WX_FILENAME_H_
|
|
|
|
|
2005-09-25 20:49:40 +00:00
|
|
|
#include "wx/arrstr.h"
|
2000-12-29 17:39:00 +00:00
|
|
|
#include "wx/filefn.h"
|
2001-04-09 17:16:09 +00:00
|
|
|
#include "wx/datetime.h"
|
2006-08-18 20:56:34 +00:00
|
|
|
#include "wx/intl.h"
|
2007-07-16 20:33:27 +00:00
|
|
|
#include "wx/longlong.h"
|
2008-09-27 10:28:43 +00:00
|
|
|
#include "wx/file.h"
|
2000-12-28 00:00:32 +00:00
|
|
|
|
2005-02-24 18:01:42 +00:00
|
|
|
#if wxUSE_FILE
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxFile;
|
2005-02-24 18:01:42 +00:00
|
|
|
#endif
|
2001-12-18 17:47:27 +00:00
|
|
|
|
2006-10-23 13:10:12 +00:00
|
|
|
#if wxUSE_FFILE
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxFFile;
|
2006-10-23 13:10:12 +00:00
|
|
|
#endif
|
|
|
|
|
2008-09-14 01:18:05 +00:00
|
|
|
// this symbol is defined for the platforms where file systems use volumes in
|
|
|
|
// paths
|
2012-03-04 00:29:31 +00:00
|
|
|
#if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
|
2008-09-14 01:18:05 +00:00
|
|
|
#define wxHAS_FILESYSTEM_VOLUMES
|
|
|
|
#endif
|
|
|
|
|
2000-12-30 19:36:10 +00: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-28 00:00:32 +00:00
|
|
|
enum wxPathFormat
|
|
|
|
{
|
2000-12-31 00:23:09 +00:00
|
|
|
wxPATH_NATIVE = 0, // the path format for the current platform
|
2000-12-30 19:36:10 +00:00
|
|
|
wxPATH_UNIX,
|
2003-07-19 17:06:29 +00:00
|
|
|
wxPATH_BEOS = wxPATH_UNIX,
|
2000-12-30 19:36:10 +00:00
|
|
|
wxPATH_MAC,
|
|
|
|
wxPATH_DOS,
|
2003-07-19 17:06:29 +00:00
|
|
|
wxPATH_WIN = wxPATH_DOS,
|
|
|
|
wxPATH_OS2 = wxPATH_DOS,
|
2001-11-23 13:45:25 +00:00
|
|
|
wxPATH_VMS,
|
2000-12-29 17:39:00 +00:00
|
|
|
|
2003-07-19 17:06:29 +00:00
|
|
|
wxPATH_MAX // Not a valid value for specifying path format
|
2000-12-30 19:36:10 +00:00
|
|
|
};
|
2000-12-29 17:39:00 +00:00
|
|
|
|
2010-04-06 22:51:11 +00:00
|
|
|
// different conventions that may be used with GetHumanReadableSize()
|
2010-04-06 14:53:04 +00:00
|
|
|
enum wxSizeConvention
|
|
|
|
{
|
2010-04-06 22:51:11 +00:00
|
|
|
wxSIZE_CONV_TRADITIONAL, // 1024 bytes = 1 KB
|
|
|
|
wxSIZE_CONV_IEC, // 1024 bytes = 1 KiB
|
|
|
|
wxSIZE_CONV_SI // 1000 bytes = 1 KB
|
2010-04-06 14:53:04 +00:00
|
|
|
};
|
|
|
|
|
2000-12-30 19:36:10 +00: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-02 01:03:00 +00:00
|
|
|
wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and .
|
2000-12-30 19:36:10 +00:00
|
|
|
wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user
|
2000-12-31 00:23:09 +00:00
|
|
|
wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower
|
|
|
|
wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute
|
2001-03-21 12:34:56 +00:00
|
|
|
wxPATH_NORM_LONG = 0x0020, // make the path the long form
|
2003-12-20 13:59:13 +00:00
|
|
|
wxPATH_NORM_SHORTCUT = 0x0040, // resolve the shortcut, if it is a shortcut
|
|
|
|
wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE
|
2000-12-28 00:00:32 +00:00
|
|
|
};
|
|
|
|
|
2002-04-08 16:15:43 +00:00
|
|
|
// what exactly should GetPath() return?
|
|
|
|
enum
|
|
|
|
{
|
2008-09-14 01:18:05 +00:00
|
|
|
wxPATH_NO_SEPARATOR = 0x0000, // for symmetry with wxPATH_GET_SEPARATOR
|
2002-04-08 16:15:43 +00:00
|
|
|
wxPATH_GET_VOLUME = 0x0001, // include the volume if applicable
|
|
|
|
wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator
|
|
|
|
};
|
|
|
|
|
2009-01-25 12:37:16 +00:00
|
|
|
// Mkdir flags
|
2002-04-08 16:28:50 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxPATH_MKDIR_FULL = 0x0001 // create directories recursively
|
|
|
|
};
|
|
|
|
|
2009-01-25 12:37:16 +00:00
|
|
|
// Rmdir flags
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxPATH_RMDIR_FULL = 0x0001, // delete with subdirectories if empty
|
|
|
|
wxPATH_RMDIR_RECURSIVE = 0x0002 // delete all recursively (dangerous!)
|
|
|
|
};
|
|
|
|
|
2012-10-19 22:02:15 +00:00
|
|
|
// FileExists flags
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxFILE_EXISTS_REGULAR = 0x0001, // check for existence of a regular file
|
|
|
|
wxFILE_EXISTS_DIR = 0x0002, // check for existence of a directory
|
2012-10-25 22:30:43 +00:00
|
|
|
wxFILE_EXISTS_SYMLINK = 0x1004, // check for existence of a symbolic link;
|
|
|
|
// also sets wxFILE_EXISTS_NO_FOLLOW as
|
|
|
|
// it would never be satisfied otherwise
|
2012-10-19 22:02:15 +00:00
|
|
|
wxFILE_EXISTS_DEVICE = 0x0008, // check for existence of a device
|
|
|
|
wxFILE_EXISTS_FIFO = 0x0016, // check for existence of a FIFO
|
|
|
|
wxFILE_EXISTS_SOCKET = 0x0032, // check for existence of a socket
|
|
|
|
// gap for future types
|
2012-10-25 22:30:43 +00:00
|
|
|
wxFILE_EXISTS_NO_FOLLOW = 0x1000, // don't dereference a contained symlink
|
|
|
|
wxFILE_EXISTS_ANY = 0x1FFF // check for existence of anything
|
2012-10-19 22:02:15 +00:00
|
|
|
};
|
|
|
|
|
2007-07-10 23:19:17 +00:00
|
|
|
#if wxUSE_LONGLONG
|
2006-08-18 20:56:34 +00:00
|
|
|
// error code of wxFileName::GetSize()
|
2007-10-20 14:34:43 +00:00
|
|
|
extern WXDLLIMPEXP_DATA_BASE(const wxULongLong) wxInvalidSize;
|
2007-07-10 23:19:17 +00:00
|
|
|
#endif // wxUSE_LONGLONG
|
2006-08-18 20:56:34 +00:00
|
|
|
|
|
|
|
|
2006-10-05 17:28:31 +00:00
|
|
|
|
2000-12-30 19:36:10 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFileName: encapsulates a file path
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFileName
|
2000-12-28 00:00:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructors and assignment
|
2000-12-31 00:23:09 +00:00
|
|
|
|
|
|
|
// the usual stuff
|
2002-08-20 13:28:51 +00:00
|
|
|
wxFileName() { Clear(); }
|
2003-07-17 23:39:28 +00:00
|
|
|
wxFileName(const wxFileName& filepath) { Assign(filepath); }
|
2000-12-31 00:23:09 +00: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 )
|
2012-10-15 01:09:01 +00:00
|
|
|
{ Assign( fullpath, format ); m_dontFollowLinks = false; }
|
2000-12-31 00:23:09 +00:00
|
|
|
|
|
|
|
// from a directory name and a file name
|
|
|
|
wxFileName(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE)
|
2012-10-15 01:09:01 +00:00
|
|
|
{ Assign(path, name, format); m_dontFollowLinks = false; }
|
2000-12-31 00:23:09 +00:00
|
|
|
|
2001-12-04 01:14:09 +00: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)
|
2012-10-15 01:09:01 +00:00
|
|
|
{ Assign(volume, path, name, ext, format); m_dontFollowLinks = false; }
|
2001-12-04 01:14:09 +00:00
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// from a directory name, file base name and extension
|
|
|
|
wxFileName(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE)
|
2012-10-15 01:09:01 +00:00
|
|
|
{ Assign(path, name, ext, format); m_dontFollowLinks = false; }
|
2000-12-31 00:23:09 +00:00
|
|
|
|
|
|
|
// the same for delayed initialization
|
|
|
|
|
|
|
|
void Assign(const wxFileName& filepath);
|
2001-11-30 21:55:13 +00:00
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
void Assign(const wxString& fullpath,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 21:55:13 +00:00
|
|
|
|
|
|
|
void Assign(const wxString& volume,
|
|
|
|
const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
2005-02-28 00:18:37 +00:00
|
|
|
bool hasExt,
|
2001-11-30 21:55:13 +00:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2005-02-28 00:18:37 +00: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-31 00:23:09 +00:00
|
|
|
void Assign(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 21:55:13 +00:00
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
void Assign(const wxString& path,
|
|
|
|
const wxString& name,
|
|
|
|
const wxString& ext,
|
2004-11-07 20:11:42 +00:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 21:55:13 +00:00
|
|
|
|
2001-12-01 02:28:51 +00:00
|
|
|
void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE);
|
2000-12-31 00:23:09 +00:00
|
|
|
|
2001-05-14 16:13:12 +00:00
|
|
|
// assorted assignment operators
|
|
|
|
|
|
|
|
wxFileName& operator=(const wxFileName& filename)
|
2008-11-16 18:03:08 +00:00
|
|
|
{ if (this != &filename) Assign(filename); return *this; }
|
2001-05-14 16:13:12 +00:00
|
|
|
|
|
|
|
wxFileName& operator=(const wxString& filename)
|
|
|
|
{ Assign(filename); return *this; }
|
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// reset all components to default, uninitialized state
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// static pseudo constructors
|
2003-07-17 23:39:28 +00:00
|
|
|
static wxFileName FileName(const wxString& file,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
static wxFileName DirName(const wxString& dir,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2000-12-31 00:23:09 +00:00
|
|
|
|
2001-10-30 02:41:30 +00:00
|
|
|
// file tests
|
2000-12-31 00:23:09 +00:00
|
|
|
|
|
|
|
// is the filename valid at all?
|
2004-02-16 18:30:18 +00:00
|
|
|
bool IsOk() const
|
2004-09-14 12:08:28 +00:00
|
|
|
{
|
2004-02-16 18:30:18 +00:00
|
|
|
// we're fine if we have the path or the name or if we're a root dir
|
2005-03-17 17:46:32 +00:00
|
|
|
return m_dirs.size() != 0 || !m_name.empty() || !m_relative ||
|
2005-02-28 00:18:37 +00:00
|
|
|
!m_ext.empty() || m_hasExt;
|
2004-02-16 18:30:18 +00:00
|
|
|
}
|
2000-12-31 00:23:09 +00:00
|
|
|
|
2012-02-15 15:39:46 +00:00
|
|
|
// does the file with this name exist?
|
2003-01-25 12:01:57 +00:00
|
|
|
bool FileExists() const;
|
2000-12-30 00:28:00 +00:00
|
|
|
static bool FileExists( const wxString &file );
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2012-02-15 15:39:46 +00:00
|
|
|
// does the directory with this name exist?
|
2003-01-25 12:01:57 +00:00
|
|
|
bool DirExists() const;
|
2000-12-30 00:28:00 +00:00
|
|
|
static bool DirExists( const wxString &dir );
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2012-02-15 15:39:46 +00:00
|
|
|
// does anything at all with this name (i.e. file, directory or some
|
|
|
|
// other file system object such as a device, socket, ...) exist?
|
2012-10-19 22:02:15 +00:00
|
|
|
bool Exists(int flags = wxFILE_EXISTS_ANY) const;
|
|
|
|
static bool Exists(const wxString& path, int flags = wxFILE_EXISTS_ANY);
|
2012-02-15 15:39:46 +00:00
|
|
|
|
|
|
|
|
2006-10-05 17:28:31 +00: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); }
|
|
|
|
|
2013-08-07 11:08:28 +00:00
|
|
|
// set the file permissions to a combination of wxPosixPermissions enum
|
|
|
|
// values
|
|
|
|
bool SetPermissions(int permissions);
|
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
|
2001-10-30 02:41:30 +00:00
|
|
|
// time functions
|
2003-02-06 00:53:46 +00:00
|
|
|
#if wxUSE_DATETIME
|
2002-03-27 23:17:41 +00:00
|
|
|
// set the file last access/mod and creation times
|
2001-10-30 02:41:30 +00:00
|
|
|
// (any of the pointers may be NULL)
|
2002-03-27 23:17:41 +00:00
|
|
|
bool SetTimes(const wxDateTime *dtAccess,
|
|
|
|
const wxDateTime *dtMod,
|
2009-06-12 15:28:45 +00:00
|
|
|
const wxDateTime *dtCreate) const;
|
2001-10-30 02:41:30 +00:00
|
|
|
|
|
|
|
// set the access and modification times to the current moment
|
2009-06-12 15:28:45 +00:00
|
|
|
bool Touch() const;
|
2001-10-30 02:41:30 +00:00
|
|
|
|
2002-03-27 23:17:41 +00:00
|
|
|
// return the last access, last modification and create times
|
2001-10-30 02:41:30 +00:00
|
|
|
// (any of the pointers may be NULL)
|
|
|
|
bool GetTimes(wxDateTime *dtAccess,
|
|
|
|
wxDateTime *dtMod,
|
2002-03-27 23:17:41 +00:00
|
|
|
wxDateTime *dtCreate) const;
|
2001-10-30 02:41:30 +00: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-06 00:53:46 +00:00
|
|
|
#endif // wxUSE_DATETIME
|
2001-10-30 02:41:30 +00:00
|
|
|
|
2008-07-29 20:22:57 +00:00
|
|
|
#if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON
|
2002-01-13 17:38:55 +00:00
|
|
|
bool MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) ;
|
2009-06-12 15:28:45 +00:00
|
|
|
bool MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) const;
|
2002-01-13 17:38:55 +00: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 13:28:51 +00:00
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// various file/dir operations
|
|
|
|
|
|
|
|
// retrieve the value of the current working directory
|
2001-12-01 03:16:19 +00:00
|
|
|
void AssignCwd(const wxString& volume = wxEmptyString);
|
|
|
|
static wxString GetCwd(const wxString& volume = wxEmptyString);
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// change the current working directory
|
2009-06-12 15:28:45 +00:00
|
|
|
bool SetCwd() const;
|
2000-12-30 00:28:00 +00:00
|
|
|
static bool SetCwd( const wxString &cwd );
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// get the value of user home (Unix only mainly)
|
2000-12-30 00:28:00 +00:00
|
|
|
void AssignHomeDir();
|
|
|
|
static wxString GetHomeDir();
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2006-10-23 17:47:02 +00:00
|
|
|
// get the system temporary directory
|
|
|
|
static wxString GetTempDir();
|
|
|
|
|
2006-10-23 13:10:12 +00: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 18:01:42 +00:00
|
|
|
#if wxUSE_FILE
|
2001-12-18 17:47:27 +00: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 13:10:12 +00:00
|
|
|
void AssignTempFileName(const wxString& prefix, wxFile *fileTemp);
|
2001-12-18 17:47:27 +00:00
|
|
|
static wxString CreateTempFileName(const wxString& prefix,
|
2006-10-23 13:10:12 +00:00
|
|
|
wxFile *fileTemp);
|
2005-02-24 18:01:42 +00:00
|
|
|
#endif // wxUSE_FILE
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2006-10-23 13:10:12 +00: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 13:31:12 +00:00
|
|
|
// directory creation and removal.
|
2009-06-11 16:11:07 +00:00
|
|
|
bool Mkdir(int perm = wxS_DIR_DEFAULT, int flags = 0) const;
|
2009-01-25 12:37:16 +00:00
|
|
|
static bool Mkdir(const wxString &dir, int perm = wxS_DIR_DEFAULT,
|
|
|
|
int flags = 0);
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2009-06-11 16:11:07 +00:00
|
|
|
bool Rmdir(int flags = 0) const;
|
2009-01-25 12:37:16 +00:00
|
|
|
static bool Rmdir(const wxString &dir, int flags = 0);
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2000-12-31 00:23:09 +00: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 23:14:45 +00:00
|
|
|
bool Normalize(int flags = wxPATH_NORM_ALL,
|
2000-12-31 00:23:09 +00:00
|
|
|
const wxString& cwd = wxEmptyString,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2001-12-04 15:13:56 +00: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 17:06:29 +00:00
|
|
|
// returns true if the file name was modified, false if we failed to do
|
2001-12-04 15:13:56 +00:00
|
|
|
// anything with it (happens when the file is on a different volume,
|
|
|
|
// for example)
|
2003-07-10 08:36:14 +00:00
|
|
|
bool MakeRelativeTo(const wxString& pathBase = wxEmptyString,
|
2001-12-04 15:13:56 +00:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2003-01-18 00:01:18 +00: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 15:13:56 +00:00
|
|
|
|
2012-10-15 01:09:01 +00:00
|
|
|
|
|
|
|
// If the path is a symbolic link (Unix-only), indicate that all
|
|
|
|
// filesystem operations on this path should be performed on the link
|
|
|
|
// itself and not on the file it points to, as is the case by default.
|
|
|
|
//
|
|
|
|
// No effect if this is not a symbolic link.
|
|
|
|
void DontFollowLink()
|
|
|
|
{
|
|
|
|
m_dontFollowLinks = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the path is a symbolic link (Unix-only), returns whether various
|
|
|
|
// file operations should act on the link itself, or on its target.
|
|
|
|
//
|
|
|
|
// This does not test if the path is really a symlink or not.
|
|
|
|
bool ShouldFollowLink() const
|
|
|
|
{
|
|
|
|
return !m_dontFollowLinks;
|
|
|
|
}
|
|
|
|
|
2004-01-26 12:44:14 +00:00
|
|
|
#if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE
|
2003-12-20 13:59:13 +00:00
|
|
|
// if the path is a shortcut, return the target and optionally,
|
|
|
|
// the arguments
|
2004-01-26 12:44:14 +00:00
|
|
|
bool GetShortcutTarget(const wxString& shortcutPath,
|
|
|
|
wxString& targetFilename,
|
2009-06-12 15:28:45 +00:00
|
|
|
wxString* arguments = NULL) const;
|
2003-12-20 13:59:13 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-07 00:38:46 +00: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-28 00:00:32 +00:00
|
|
|
// Comparison
|
2000-12-31 00:23:09 +00:00
|
|
|
|
2002-12-04 14:11:26 +00: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-31 00:23:09 +00:00
|
|
|
|
2001-11-30 21:55:13 +00:00
|
|
|
// are the file names of this type cases sensitive?
|
2000-12-31 00:23:09 +00:00
|
|
|
static bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE );
|
2001-11-30 21:55:13 +00:00
|
|
|
|
|
|
|
// is this filename absolute?
|
2002-03-28 11:44:30 +00:00
|
|
|
bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE) const;
|
2000-12-31 00:23:09 +00:00
|
|
|
|
2001-11-30 21:55:13 +00:00
|
|
|
// is this filename relative?
|
2002-03-28 11:44:30 +00:00
|
|
|
bool IsRelative(wxPathFormat format = wxPATH_NATIVE) const
|
|
|
|
{ return !IsAbsolute(format); }
|
2001-11-30 21:55:13 +00:00
|
|
|
|
2003-07-19 17:06:29 +00:00
|
|
|
// Returns the characters that aren't allowed in filenames
|
|
|
|
// on the specified platform.
|
|
|
|
static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2001-11-30 21:55:13 +00:00
|
|
|
// Information about path format
|
|
|
|
|
2002-03-28 11:44:30 +00: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 21:55:13 +00:00
|
|
|
static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// get the string of path separators for this format
|
|
|
|
static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2004-07-25 13:59:47 +00:00
|
|
|
// get the string of path terminators, i.e. characters which terminate the
|
|
|
|
// path
|
|
|
|
static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2002-03-28 11:44:30 +00:00
|
|
|
// get the canonical path separator for this format
|
2007-03-17 10:26:10 +00:00
|
|
|
static wxUniChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE)
|
2002-03-28 11:44:30 +00:00
|
|
|
{ return GetPathSeparators(format)[0u]; }
|
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// is the char a path separator for this format?
|
|
|
|
static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2009-12-05 17:31:00 +00: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-28 00:00:32 +00: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 19:52:35 +00:00
|
|
|
size_t GetDirCount() const { return m_dirs.size(); }
|
2013-03-09 15:08:36 +00:00
|
|
|
bool AppendDir(const wxString& dir);
|
2005-02-13 00:55:27 +00:00
|
|
|
void PrependDir(const wxString& dir);
|
2013-03-09 15:08:36 +00:00
|
|
|
bool InsertDir(size_t before, const wxString& dir);
|
2005-02-13 00:55:27 +00:00
|
|
|
void RemoveDir(size_t pos);
|
|
|
|
void RemoveLastDir() { RemoveDir(GetDirCount() - 1); }
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2000-12-28 00:00:32 +00:00
|
|
|
// Other accessors
|
2005-03-04 17:31:18 +00:00
|
|
|
void SetExt( const wxString &ext ) { m_ext = ext; m_hasExt = !m_ext.empty(); }
|
2013-03-09 15:08:40 +00:00
|
|
|
void ClearExt() { m_ext.clear(); m_hasExt = false; }
|
|
|
|
void SetEmptyExt() { m_ext.clear(); m_hasExt = true; }
|
2000-12-28 00:00:32 +00:00
|
|
|
wxString GetExt() const { return m_ext; }
|
2005-03-03 19:45:24 +00:00
|
|
|
bool HasExt() const { return m_hasExt; }
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2000-12-28 00:00:32 +00:00
|
|
|
void SetName( const wxString &name ) { m_name = name; }
|
|
|
|
wxString GetName() const { return m_name; }
|
2001-11-30 21:55:13 +00: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 19:36:10 +00:00
|
|
|
|
2000-12-31 15:23:43 +00:00
|
|
|
// full name is the file name + extension (but without the path)
|
|
|
|
void SetFullName(const wxString& fullname);
|
2000-12-31 00:23:09 +00:00
|
|
|
wxString GetFullName() const;
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2001-11-30 21:55:13 +00:00
|
|
|
const wxArrayString& GetDirs() const { return m_dirs; }
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2002-04-08 16:15:43 +00:00
|
|
|
// flags are combination of wxPATH_GET_XXX flags
|
2003-07-27 22:53:23 +00:00
|
|
|
wxString GetPath(int flags = wxPATH_GET_VOLUME,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE) const;
|
2002-04-08 16:15:43 +00:00
|
|
|
|
2001-12-23 15:52:29 +00:00
|
|
|
// Replace current path with this one
|
|
|
|
void SetPath( const wxString &path, wxPathFormat format = wxPATH_NATIVE );
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2000-12-28 00:00:32 +00:00
|
|
|
// Construct full path with name and ext
|
|
|
|
wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const;
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2001-03-21 12:34:56 +00: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 11:14:09 +00:00
|
|
|
// Is this a file or directory (not necessarily an existing one)
|
|
|
|
bool IsDir() const { return m_name.empty() && m_ext.empty(); }
|
|
|
|
|
2000-12-31 01:15:33 +00:00
|
|
|
// various helpers
|
|
|
|
|
|
|
|
// get the canonical path format for this platform
|
2000-12-28 00:00:32 +00:00
|
|
|
static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE );
|
2000-12-30 19:36:10 +00:00
|
|
|
|
2001-11-30 21:55:13 +00:00
|
|
|
// split a fullpath into the volume, path, (base) name and extension
|
|
|
|
// (all of the pointers can be NULL)
|
2000-12-31 01:15:33 +00:00
|
|
|
static void SplitPath(const wxString& fullpath,
|
2001-11-30 21:55:13 +00:00
|
|
|
wxString *volume,
|
2000-12-31 01:15:33 +00:00
|
|
|
wxString *path,
|
|
|
|
wxString *name,
|
|
|
|
wxString *ext,
|
2005-02-28 00:18:37 +00:00
|
|
|
bool *hasExt = NULL,
|
2000-12-31 01:15:33 +00:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
2005-02-28 00:18:37 +00:00
|
|
|
static void SplitPath(const wxString& fullpath,
|
|
|
|
wxString *volume,
|
|
|
|
wxString *path,
|
|
|
|
wxString *name,
|
|
|
|
wxString *ext,
|
2005-02-28 17:23:19 +00:00
|
|
|
wxPathFormat format)
|
2005-02-28 00:18:37 +00:00
|
|
|
{
|
|
|
|
SplitPath(fullpath, volume, path, name, ext, NULL, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
// compatibility version: volume is part of path
|
2001-11-30 21:55:13 +00:00
|
|
|
static void SplitPath(const wxString& fullpath,
|
|
|
|
wxString *path,
|
|
|
|
wxString *name,
|
|
|
|
wxString *ext,
|
2001-12-01 03:16:19 +00:00
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
2001-11-30 21:55:13 +00:00
|
|
|
|
2004-07-25 13:59:47 +00: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 16:15:43 +00:00
|
|
|
|
2009-03-26 16:02:09 +00:00
|
|
|
// strip the file extension: "foo.bar" => "foo" (but ".baz" => ".baz")
|
2009-03-26 15:55:01 +00:00
|
|
|
static wxString StripExtension(const wxString& fullpath);
|
|
|
|
|
2008-09-14 01:18:05 +00: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 20:56:34 +00:00
|
|
|
|
2007-07-10 23:19:17 +00:00
|
|
|
#if wxUSE_LONGLONG
|
2006-08-18 20:56:34 +00: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 14:53:04 +00:00
|
|
|
wxString
|
2013-09-15 00:15:02 +00:00
|
|
|
GetHumanReadableSize(const wxString& nullsize = wxGetTranslation("Not available"),
|
2010-04-06 14:53:04 +00:00
|
|
|
int precision = 1,
|
2010-04-06 22:51:11 +00:00
|
|
|
wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL) const;
|
2010-04-06 14:53:04 +00:00
|
|
|
static wxString
|
|
|
|
GetHumanReadableSize(const wxULongLong& sz,
|
2013-09-15 00:15:02 +00:00
|
|
|
const wxString& nullsize = wxGetTranslation("Not available"),
|
2010-04-06 14:53:04 +00:00
|
|
|
int precision = 1,
|
2010-04-06 22:51:11 +00:00
|
|
|
wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL);
|
2007-07-10 23:19:17 +00:00
|
|
|
#endif // wxUSE_LONGLONG
|
2006-08-18 20:56:34 +00:00
|
|
|
|
|
|
|
|
2002-04-08 16:15:43 +00:00
|
|
|
// deprecated methods, don't use any more
|
|
|
|
// --------------------------------------
|
|
|
|
|
2003-04-19 18:15:17 +00:00
|
|
|
#ifndef __DIGITALMARS__
|
2002-04-08 16:15:43 +00:00
|
|
|
wxString GetPath( bool withSep, wxPathFormat format = wxPATH_NATIVE ) const
|
|
|
|
{ return GetPath(withSep ? wxPATH_GET_SEPARATOR : 0, format); }
|
2003-04-19 18:15:17 +00:00
|
|
|
#endif
|
2002-04-08 16:15:43 +00:00
|
|
|
wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const
|
2006-05-03 13:11:18 +00:00
|
|
|
{ return GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format); }
|
2002-04-08 16:15:43 +00:00
|
|
|
|
2000-12-28 00:00:32 +00:00
|
|
|
private:
|
2003-10-08 23:15:16 +00:00
|
|
|
// check whether this dir is valid for Append/Prepend/InsertDir()
|
|
|
|
static bool IsValidDirComponent(const wxString& dir);
|
|
|
|
|
2001-11-30 21:55:13 +00:00
|
|
|
// the drive/volume/device specification (always empty for Unix)
|
|
|
|
wxString m_volume;
|
|
|
|
|
2000-12-31 00:23:09 +00:00
|
|
|
// the path components of the file
|
2000-12-28 00:00:32 +00:00
|
|
|
wxArrayString m_dirs;
|
2000-12-31 00:23:09 +00:00
|
|
|
|
|
|
|
// the file name and extension (empty for directories)
|
|
|
|
wxString m_name,
|
|
|
|
m_ext;
|
2002-03-28 11:44:30 +00: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 17:06:29 +00:00
|
|
|
// true in the former and false in the latter
|
2002-03-28 11:44:30 +00:00
|
|
|
//
|
2003-07-19 17:06:29 +00:00
|
|
|
// NB: the path is not absolute just because m_relative is false, it still
|
2002-03-28 11:44:30 +00:00
|
|
|
// needs the drive (i.e. volume) in some formats (Windows)
|
2001-12-16 12:07:44 +00:00
|
|
|
bool m_relative;
|
2005-02-28 00:18:37 +00: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;
|
2012-10-15 01:09:01 +00:00
|
|
|
|
|
|
|
// by default, symlinks are dereferenced but this flag can be set with
|
|
|
|
// DontFollowLink() to change this and make different operations work on
|
|
|
|
// this file path itself instead of the target of the symlink
|
|
|
|
bool m_dontFollowLinks;
|
2000-12-28 00:00:32 +00:00
|
|
|
};
|
|
|
|
|
2000-12-30 19:36:10 +00:00
|
|
|
#endif // _WX_FILENAME_H_
|
2000-12-28 00:00:32 +00:00
|
|
|
|