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-27 19:00:32 -05:00
|
|
|
// Author: Robert Roebling
|
|
|
|
// Modified by:
|
|
|
|
// Created: 28.12.00
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000 Robert Roebling
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_FILENAME_H_
|
|
|
|
#define _WX_FILENAME_H_
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "filename.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/string.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ridiculously enough, this will replace DirExists with wxDirExists etc
|
2000-12-29 12:39:00 -05:00
|
|
|
#include "wx/filefn.h"
|
2000-12-27 19:00:32 -05:00
|
|
|
|
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 14:36:10 -05:00
|
|
|
wxPATH_NATIVE = 0,
|
|
|
|
wxPATH_UNIX,
|
|
|
|
wxPATH_MAC,
|
|
|
|
wxPATH_DOS,
|
2000-12-29 12:39:00 -05:00
|
|
|
|
2000-12-30 14:36:10 -05:00
|
|
|
wxPATH_BEOS = wxPATH_UNIX,
|
|
|
|
wxPATH_WIN = wxPATH_DOS,
|
|
|
|
wxPATH_OS2 = wxPATH_DOS
|
|
|
|
};
|
2000-12-29 12:39:00 -05:00
|
|
|
|
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
|
|
|
|
wxPATH_NORM_ABSOLUTE = 0x0002, // squeeze all .. and . and prepend cwd
|
|
|
|
wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user
|
|
|
|
wxPATH_NORM_ALL = 0x0007
|
2000-12-27 19:00:32 -05:00
|
|
|
};
|
|
|
|
|
2000-12-30 14:36:10 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFileName: encapsulates a file path
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
class WXDLLEXPORT wxFileName
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructors and assignment
|
2000-12-30 14:36:10 -05:00
|
|
|
wxFileName()
|
2000-12-27 19:00:32 -05:00
|
|
|
{ }
|
2000-12-29 19:28:00 -05:00
|
|
|
wxFileName( const wxFileName &filepath );
|
2000-12-27 19:00:32 -05:00
|
|
|
wxFileName( const wxString &path, bool dir_only = FALSE, wxPathFormat format = wxPATH_NATIVE )
|
|
|
|
{ Assign( path, dir_only, format ); }
|
|
|
|
void Assign( const wxString &path, bool dir_only = FALSE, wxPathFormat format = wxPATH_NATIVE );
|
2000-12-29 19:28:00 -05:00
|
|
|
void Assign( const wxFileName &filepath );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Only native form
|
|
|
|
bool FileExists();
|
2000-12-29 19:28:00 -05:00
|
|
|
static bool FileExists( const wxString &file );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
bool DirExists();
|
2000-12-29 19:28:00 -05:00
|
|
|
static bool DirExists( const wxString &dir );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
void AssignCwd();
|
2000-12-29 19:28:00 -05:00
|
|
|
static wxString GetCwd();
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-29 19:28:00 -05:00
|
|
|
bool SetCwd();
|
|
|
|
static bool SetCwd( const wxString &cwd );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-29 19:28:00 -05:00
|
|
|
void AssignHomeDir();
|
|
|
|
static wxString GetHomeDir();
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
void AssignTempFileName( const wxString &prefix );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-29 19:28:00 -05:00
|
|
|
bool Mkdir( int perm = 0777 );
|
|
|
|
static bool Mkdir( const wxString &dir, int perm = 0777 );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-29 19:28:00 -05:00
|
|
|
bool Rmdir();
|
|
|
|
static bool Rmdir( const wxString &dir );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Remove . and .. (under Unix ~ as well)
|
2000-12-29 19:28:00 -05:00
|
|
|
bool Normalize( const wxString &cwd = wxEmptyString, const wxString &home = wxEmptyString );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Comparison
|
2000-12-29 19:28:00 -05:00
|
|
|
bool SameAs( const wxFileName &filepath, bool upper_case = TRUE );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Tests
|
|
|
|
bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE );
|
|
|
|
bool IsRelative( wxPathFormat format = wxPATH_NATIVE );
|
|
|
|
bool IsAbsolute( wxPathFormat format = wxPATH_NATIVE );
|
|
|
|
bool IsWild( wxPathFormat format = wxPATH_NATIVE );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Dir accessors
|
|
|
|
void AppendDir( const wxString &dir );
|
|
|
|
void PrependDir( const wxString &dir );
|
|
|
|
void InsertDir( int before, const wxString &dir );
|
|
|
|
void RemoveDir( int pos );
|
2000-12-30 14:36:10 -05:00
|
|
|
size_t GetDirCount() const { return m_dirs.GetCount(); }
|
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Other accessors
|
|
|
|
void SetExt( const wxString &ext ) { m_ext = ext; }
|
|
|
|
wxString GetExt() const { return m_ext; }
|
|
|
|
bool HasExt() const { return !m_ext.IsEmpty(); }
|
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; }
|
|
|
|
bool HasName() const { return !m_name.IsEmpty(); }
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-29 19:28:00 -05:00
|
|
|
// name and ext
|
|
|
|
void SetFullName( const wxString name, wxPathFormat format = wxPATH_NATIVE );
|
|
|
|
wxString GetFullName();
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
const wxArrayString &GetDirs() const { return m_dirs; }
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
// Construct path only
|
2000-12-29 19:28:00 -05:00
|
|
|
wxString GetPath( bool add_separator = FALSE, wxPathFormat format = wxPATH_NATIVE ) const;
|
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
|
|
|
|
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE );
|
2000-12-30 14:36:10 -05:00
|
|
|
|
2000-12-27 19:00:32 -05:00
|
|
|
private:
|
|
|
|
wxArrayString m_dirs;
|
|
|
|
wxString m_name;
|
|
|
|
wxString m_ext;
|
|
|
|
};
|
|
|
|
|
2000-12-30 14:36:10 -05:00
|
|
|
#endif // _WX_FILENAME_H_
|
2000-12-27 19:00:32 -05:00
|
|
|
|