/////////////////////////////////////////////////////////////////////////////
// Name: filename.h
-// Purpose: documentation for wxFileName class
+// Purpose: interface of wxFileName
// Author: wxWidgets team
// RCS-ID: $Id$
// Licence: wxWindows license
a complete file name (such as when interpreting user input) you need to use
the static function wxFileName::DirExists
(or its identical variants wxDir::Exists and
- wxDirExists) and construct the wxFileName
+ wxDirExists()) and construct the wxFileName
instance accordingly. This will only work if the directory actually exists,
of course:
@library{wxbase}
@category{file}
- @seealso
- wxFileName::GetCwd
+ @see wxFileName::GetCwd
*/
class wxFileName
{
/**
Makes this object refer to the current working directory on the specified
volume (or current volume if @a volume is empty).
-
+
@see GetCwd()
*/
static void AssignCwd(const wxString& volume = wxEmptyString);
/**
Removes the extension from the file name resulting in a
file name with no trailing dot.
-
+
@see SetExt(), SetEmptyExt()
*/
void SetClearExt();
If @a fileTemp is @NULL, the file is only created, but not opened.
Under Unix, the temporary file will have read and write permissions for the
owner only to minimize the security problems.
-
+
@param prefix
Prefix to use for the temporary file name construction
@param fileTemp
The file to open or @NULL to just get the name
-
- @returns The full temporary file name or an empty string on error.
+
+ @return The full temporary file name or an empty string on error.
*/
static wxString CreateTempFileName(const wxString& prefix,
wxFile* fileTemp = NULL);
Returns @true if the directory with this name exists.
*/
bool DirExists();
- static bool DirExists(const wxString& dir);
+ const static bool DirExists(const wxString& dir);
//@}
/**
These functions allow to examine and modify the individual directories of the
path:
AppendDir()
-
+
InsertDir()
-
+
GetDirCount()
PrependDir()
-
+
RemoveDir()
-
+
RemoveLastDir()
To change the components of the file name individually you can use the
following functions:
GetExt()
-
+
GetName()
-
+
GetVolume()
-
+
HasExt()
-
+
HasName()
-
+
HasVolume()
-
+
SetExt()
-
+
ClearExt()
-
+
SetEmptyExt()
-
+
SetName()
-
+
SetVolume()
*/
/**
You can initialize a wxFileName instance using one of the following functions:
@ref wxfilename() "wxFileName constructors"
-
+
Assign()
-
+
AssignCwd()
-
+
AssignDir()
-
+
AssignHomeDir()
-
+
@ref assigntempfilename() AssignHomeTempFileName
-
+
DirName()
-
+
FileName()
-
+
@ref operatorassign() "operator ="
*/
or @ref operatorequal() "operator ==".
For testing basic access modes, you can use:
IsDirWritable()
-
+
IsDirReadable()
-
+
IsFileWritable()
-
+
IsFileReadable()
-
+
IsFileExecutable()
*/
//@{
/**
Returns @true if the file with this name exists.
-
+
@see DirExists()
*/
bool FileExists();
- static bool FileExists(const wxString& file);
+ const static bool FileExists(const wxString& file);
//@}
/**
Retrieves the value of the current working directory on the specified volume. If
the volume is empty, the program's current working directory is returned for the
current volume.
-
- @returns The string containing the current working directory or an empty
+
+ @return The string containing the current working directory or an empty
string on error.
-
+
@see AssignCwd()
*/
static wxString GetCwd(const wxString& volume = "");
/**
Returns the number of directories in the file name.
*/
- size_t GetDirCount();
+ size_t GetDirCount() const;
/**
Returns the directories in string array form.
*/
- const wxArrayString GetDirs();
+ const wxArrayString GetDirs() const;
/**
Returns the file name extension.
*/
- wxString GetExt();
+ wxString GetExt() const;
/**
Returns the characters that can't be used in filenames and directory names for
/**
Returns the full name (including extension but excluding directories).
*/
- wxString GetFullName();
+ wxString GetFullName() const;
/**
Returns the full path with name and extension.
*/
- wxString GetFullPath(wxPathFormat format = wxPATH_NATIVE);
+ wxString GetFullPath(wxPathFormat format = wxPATH_NATIVE) const;
/**
Returns the home directory.
*/
wxString GetHumanReadableSize(const wxString& failmsg = "Not available",
int precision = 1);
- static wxString GetHumanReadableSize(const wxULongLong& bytes,
- const wxString& nullsize = "Not available",
- int precision = 1);
+ const static wxString GetHumanReadableSize(const wxULongLong& bytes,
+ const wxString& nullsize = "Not available",
+ int precision = 1);
//@}
/**
Return the long form of the path (returns identity on non-Windows platforms)
*/
- wxString GetLongPath();
+ wxString GetLongPath() const;
/**
Returns the last time the file was last modified.
*/
- wxDateTime GetModificationTime();
+ wxDateTime GetModificationTime() const;
/**
Returns the name part of the filename (without extension).
-
+
@see GetFullName()
*/
- wxString GetName();
+ wxString GetName() const;
/**
Returns the path part of the filename (without the name or extension). The
possible flags values are:
-
+
@b wxPATH_GET_VOLUME
-
+
Return the path with the volume (does
nothing for the filename formats without volumes), otherwise the path without
volume part is returned.
-
+
@b wxPATH_GET_SEPARATOR
-
+
Return the path with the trailing
separator, if this flag is not given there will be no separator at the end of
the path.
*/
wxString GetPath(int flags = wxPATH_GET_VOLUME,
- wxPathFormat format = wxPATH_NATIVE);
+ wxPathFormat format = wxPATH_NATIVE) const;
/**
Returns the usually used path separator for this format. For all formats but
@c wxPATH_DOS there is only one path separator anyhow, but for DOS there
are two of them and the native one, i.e. the backslash is returned by this
method.
-
+
@see GetPathSeparators()
*/
static wxChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE);
formats but @c wxPATH_DOS this string contains only one character but for
DOS and Windows both @c '/' and @c '\' may be used as
separators.
-
+
@see GetPathSeparator()
*/
static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
This is the same as calling GetPath()
@c (wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format).
*/
- wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE);
+ wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE) const;
/**
Return the short form of the path (returns identity on non-Windows platforms).
*/
- wxString GetShortPath();
+ wxString GetShortPath() const;
//@{
/**
by another process) the returned value is @c wxInvalidSize.
*/
wxULongLong GetSize();
- static wxULongLong GetSize(const wxString& filename);
+ const static wxULongLong GetSize(const wxString& filename);
//@}
/**
file specified by GetFullPath().
Any of the pointers may be @NULL if the corresponding time is not
needed.
-
- @returns @true on success, @false if we failed to retrieve the times.
+
+ @return @true on success, @false if we failed to retrieve the times.
*/
bool GetTimes(wxDateTime* dtAccess, wxDateTime* dtMod,
- wxDateTime* dtCreate);
+ wxDateTime* dtCreate) const;
/**
Returns the string containing the volume for this file name, empty if it
doesn't have one or if the file system doesn't support volumes at all (for
example, Unix).
*/
- wxString GetVolume();
+ wxString GetVolume() const;
/**
Returns the string separating the volume from the path for this format.
/**
Returns @true if an extension is present.
*/
- bool HasExt();
+ bool HasExt() const;
/**
Returns @true if a name is present.
*/
- bool HasName();
+ bool HasName() const;
/**
Returns @true if a volume specifier is present.
*/
- bool HasVolume();
+ bool HasVolume() const;
/**
Inserts a directory component before the zero-based position in the directory
DirExists() or
FileExists() for this.
*/
- bool IsDir();
+ bool IsDir() const;
//@{
/**
doesn't imply that you have read permissions on the files contained.
*/
bool IsDirReadable();
- static bool IsDirReadable(const wxString& dir);
+ const static bool IsDirReadable(const wxString& dir);
//@}
//@{
directory.
*/
bool IsDirWritable();
- static bool IsDirWritable(const wxString& dir);
+ const static bool IsDirWritable(const wxString& dir);
//@}
//@{
permissions on it.
*/
bool IsFileExecutable();
- static bool IsFileExecutable(const wxString& file);
+ const static bool IsFileExecutable(const wxString& file);
//@}
//@{
permissions on it.
*/
bool IsFileReadable();
- static bool IsFileReadable(const wxString& file);
+ const static bool IsFileReadable(const wxString& file);
//@}
//@{
permissions on it.
*/
bool IsFileWritable();
- static bool IsFileWritable(const wxString& file);
+ const static bool IsFileWritable(const wxString& file);
//@}
/**
Clear() may reset the object to the uninitialized,
invalid state (the former only do it on failure).
*/
- bool IsOk();
+ bool IsOk() const;
/**
Returns @true if the char is a path separator for this format.
Make the file name absolute. This is a shortcut for
@c wxFileName::Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
wxPATH_NORM_TILDE, cwd, format).
-
+
@see MakeRelativeTo(), Normalize(), IsAbsolute()
*/
bool MakeAbsolute(const wxString& cwd = wxEmptyString,
/**
This function tries to put this file name in a form relative to
-
+
@param pathBase.
In other words, it returns the file name which should be used to access this
file if the current directory were pathBase.
-
+
pathBase
the directory to use as root, current directory is used by
default
@param format
the file name format, native by default
-
- @returns @true if the file name has been changed, @false if we failed to do
+
+ @return @true if the file name has been changed, @false if we failed to do
anything with it (currently this only happens if the
file name is on a volume different from the volume
specified by pathBase).
-
+
@see Normalize()
*/
bool MakeRelativeTo(const wxString& pathBase = wxEmptyString,
if the flags contain wxPATH_MKDIR_FULL flag,
try to create each directory in the path and also don't return an error
if the target directory already exists.
-
- @returns Returns @true if the directory was successfully created, @false
+
+ @return Returns @true if the directory was successfully created, @false
otherwise.
*/
bool Mkdir(int perm = 0777, int flags = 0);
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.
-
+
@param flags
The kind of normalization to do with the file name. It can be
any or-combination of the following constants:
-
-
-
-
-
-
+
+
+
+
+
+
wxPATH_NORM_ENV_VARS
-
-
-
-
+
+
+
+
replace env vars with their values
-
-
-
-
-
+
+
+
+
+
wxPATH_NORM_DOTS
-
-
-
-
+
+
+
+
squeeze all .. and . when possible; if there are too many .. and thus they
cannot be all removed, @false will be returned
-
-
-
-
-
+
+
+
+
+
wxPATH_NORM_CASE
-
-
-
-
+
+
+
+
if filesystem is case insensitive, transform to lower case
-
-
-
-
-
+
+
+
+
+
wxPATH_NORM_ABSOLUTE
-
-
-
-
+
+
+
+
make the path absolute prepending cwd
-
-
-
-
-
+
+
+
+
+
wxPATH_NORM_LONG
-
-
-
-
+
+
+
+
make the path the long form
-
-
-
-
-
+
+
+
+
+
wxPATH_NORM_SHORTCUT
-
-
-
-
+
+
+
+
resolve if it is a shortcut (Windows only)
-
-
-
-
-
+
+
+
+
+
wxPATH_NORM_TILDE
-
-
-
-
+
+
+
+
replace ~ and ~user (Unix only)
-
-
-
-
-
+
+
+
+
+
wxPATH_NORM_ALL
-
-
-
-
+
+
+
+
all of previous flags except wxPATH_NORM_CASE
@param cwd
If not empty, this directory will be used instead of current
working directory in normalization (see wxPATH_NORM_ABSOLUTE).
@param format
The file name format to use when processing the paths, native by default.
-
- @returns @true if normalization was successfully or @false otherwise.
+
+ @return @true if normalization was successfully or @false otherwise.
*/
bool Normalize(int flags = wxPATH_NORM_ALL,
const wxString& cwd = wxEmptyString,
one day (so it is really the access date and not time). The access time may be
updated when the file is executed or not depending on the platform.
GetModificationTime()
-
+
GetTimes()
-
+
SetTimes()
-
+
Touch()
Other file system operations functions are:
Mkdir()
-
+
Rmdir()
*/
/**
Removes the specified directory component from the path.
-
+
@see GetDirCount()
*/
void RemoveDir(size_t pos);
Compares the filename using the rules of this platform.
*/
bool SameAs(const wxFileName& filepath,
- wxPathFormat format = wxPATH_NATIVE);
+ wxPathFormat format = wxPATH_NATIVE) const;
//@{
/**
Sets the extension of the file name to be an empty extension.
This is different from having no extension at all as the file
name will have a trailing dot after a call to this method.
-
+
@see SetExt(), ClearExt()
*/
void SetEmptyExt();
as the extension will remove the extension resulting in a file
name without a trailing dot, unlike a call to
SetEmptyExt().
-
+
@see SetEmptyExt(), ClearExt()
*/
void SetExt(const wxString& ext);
/**
Sets the name part (without extension).
-
+
@see SetFullName()
*/
void SetName(const wxString& name);
without leading dot. All three of them may be empty if the corresponding
component is. The old contents of the strings pointed to by these parameters
will be overwritten in any case (if the pointers are not @NULL).
- Note that for a filename "foo.'' the extension is present, as indicated by the
+ Note that for a filename "foo." the extension is present, as indicated by the
trailing dot, but empty. If you need to cope with such cases, you should use
@a hasExt instead of relying on testing whether @a ext is empty or not.
*/
/**
Splits the given @a fullpath into the volume part (which may be empty) and
the pure path part, not containing any volume.
-
+
@see SplitPath()
*/
static void SplitVolume(const wxString& fullpath,
Returns @true if the filenames are different. The string @e filenames
is interpreted as a path in the native filename format.
*/
- bool operator operator!=(const wxFileName& filename);
- bool operator operator!=(const wxString& filename);
+ bool operator operator!=(const wxFileName& filename) const;
+ const bool operator operator!=(const wxString& filename) const;
//@}
//@{
Returns @true if the filenames are equal. The string @e filenames is
interpreted as a path in the native filename format.
*/
- bool operator operator==(const wxFileName& filename);
- bool operator operator==(const wxString& filename);
+ bool operator operator==(const wxFileName& filename) const;
+ const bool operator operator==(const wxString& filename) const;
//@}
};
+