OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TFileName Class Reference

The TFileName class constructs filenames. More...

#include <owl/filename.h>

Public Types

enum  TSpecialType { TempFile , TempDir , CurrentDir , BootDir , MachineDir , HomeDir , SharedDir , SysDir , ComputerName }
 Construct a filename representing a special file or directory. More...
 
enum  TPart { Server = 1 , Device = 2 , Path = 4 , File = 8 , Ext =16 }
 Obtain any combination of various filename parts. More...
 
enum  { ReplaceExisting =1 , CopyAllowed =2 , DelayUntilReboot =4 }
 

Public Member Functions

 TFileName ()
 Constructs an empty filename.
 
 TFileName (LPCTSTR serverName, LPCTSTR shareOrDeviceName, LPCTSTR path, LPCTSTR file, LPCTSTR ext)
 Constructs a filename from its parts.
 
 TFileName (LPCTSTR freeform, bool pathOnly=false)
 Construct a filename given the full path in any form.
 
 TFileName (const tstring &freeform, bool pathOnly=false)
 Construct a filename given the full path in any form.
 
 TFileName (const TFileName &src)
 Constructs a filename from another filename.
 
TFileNameoperator= (const TFileName &src)
 Assigns new filename or freeform to this name.
 
TFileNameoperator= (const tstring &src)
 Assigns new filename or freeform to this name.
 
TFileNameoperator= (LPCTSTR src)
 Assigns new filename or freeform to this name.
 
 TFileName (TSpecialType type)
 Construct a filename representing a special file or directory.
 
tcharGetNameNoExt ()
 
tcharGetNameAndExt () const
 
tcharGetFullFileName ()
 
tcharGetFullFileNameNoExt ()
 
void FormCanonicalName ()
 
const tstringCanonical (bool forceUNC=false) const
 Return normal fully qualified path string.
 
const tcharCanonicalStr (bool forceUNC=false) const
 
const tcharShortName (bool forceUNC=false) const
 Returns the short file path.
 
const tcharTitle () const
 The Title member function uses system conventions to get a human-readable rendering of the filename appropriate for use in titles.
 
const tcharSqueezed (int maxLen, bool keepName=true) const
 Obtains a human-readable form of the filename.
 
const tcharGetParts (uint p) const
 Reassembles any logical subset of filename parts.
 
bool HasParts (uint p) const
 Returns true if any of the parts specified by p are used.
 
TFileNameSetPart (uint p, const tstring &partStr)
 Replaces the specified filename parts with parts extracted from partStr.
 
TFileNameMergeParts (uint p, const TFileName &source)
 Replaces the specified parts in this with the parts from source.
 
TFileNameStripParts (uint p)
 Removes the specified filename parts from this set of parts.
 
TFileNameAddSubDir (const tstring &subdir)
 
bool IsValid () const
 Determines whether a filename is valid.
 
bool IsUNC () const
 Determines whether the name is UNC format as opposed to a logical-drive based machine.
 
bool Exists () const
 Determines whether the device, directory, or file exists.
 
bool operator== (const TFileName &other) const
 Returns true if this filename is canonically equal to other.
 
bool Remove () const
 Deletes this file associated with this name if possible; otherwise attempts to delete the directory associated with this name (which must be empty).
 
bool Move (const TFileName &newName, uint32 how=CopyAllowed)
 Move (rename) the file associated with this filename, and change this name to the new name.
 
bool Copy (const TFileName &newName, bool failIfExists) const
 Copy the file associated with this filename to a new file.
 
int ChangeDir () const
 Changes the current directory to the directory associated with this filename.
 
int CreateDir () const
 Creates the directory associated with this filename.
 
int GetStatus (TFileStatus &status) const
 Get the file status struct for the item associated with this filename.
 
int SetStatus (const TFileStatus &status)
 Fills the status structure for the file associated with this filename with information from status.
 

Static Public Member Functions

static LPCTSTR WildName ()
 General wildstring.
 
static LPCTSTR WildPart (uint)
 Part specific?
 

Protected Member Functions

void Parse (LPCTSTR freeform, bool pathOnly=false)
 Parses the freeform string into the filename parts.
 

Protected Attributes

tstring ServerStr
 Holds the server filename part.
 
tstring DeviceStr
 Holds the device filename part.
 
tstring PathStr
 Holds the path filename part.
 
tstring FileStr
 Holds the file filename part (no extension).
 
tstring ExtStr
 Holds the extension filename part.
 
tstring FullCanonicalName
 
tchar NameBuffer [_MAX_PATH]
 
bool Unc
 true if UNC naming convention in use; false otherwise.
 

Detailed Description

The TFileName class constructs filenames.

Definition at line 37 of file filename.h.

Member Enumeration Documentation

◆ anonymous enum

Enumerator
ReplaceExisting 
CopyAllowed 
DelayUntilReboot 

Definition at line 153 of file filename.h.

◆ TPart

Obtain any combination of various filename parts.

Seperators inserted only as appropriate

Enumerator
Server 

Server name.

Device 

Logical device or sharename.

Path 

Directory path to the file.

File 

Filename part without the extension.

Ext 

Extension.

Definition at line 125 of file filename.h.

◆ TSpecialType

Construct a filename representing a special file or directory.

Enumerator
TempFile 

A temporary filename.

TempDir 

Location of temporary files.

CurrentDir 

Current working directory if any.

BootDir 

Root dir of boot device (LDID_BOOT)

MachineDir 

(LDID_MACHINE) currently not implemented?

HomeDir 

Home directory for OS (LDID_WIN)

SharedDir 

Shared home directory for OS (LDID_SHARED) currently not implemented?

SysDir 

Location of system files (LDID_SYS)

ComputerName 

Definition at line 91 of file filename.h.

Constructor & Destructor Documentation

◆ TFileName() [1/6]

owl::TFileName::TFileName ( )

Constructs an empty filename.

Definition at line 225 of file filename.cpp.

◆ TFileName() [2/6]

owl::TFileName::TFileName ( LPCTSTR serverName,
LPCTSTR deviceName,
LPCTSTR path,
LPCTSTR file,
LPCTSTR ext )

Constructs a filename from its parts.

Use 0 to skip any of the parameters. The form is:

where:

devicename := name(: | \ | :\)
path := multiname\[...]
ext := [.[name]]
name := (filecharset)[...]
multiname := (filecharset | .)[...]

Definition at line 264 of file filename.cpp.

References DeviceStr, ExtStr, FileStr, FormCanonicalName(), PathStr, ServerStr, and Unc.

◆ TFileName() [3/6]

owl::TFileName::TFileName ( LPCTSTR freeform,
bool pathOnly = false )

Construct a filename given the full path in any form.

Definition at line 362 of file filename.cpp.

References Parse().

◆ TFileName() [4/6]

owl::TFileName::TFileName ( const tstring & freeform,
bool pathOnly = false )

Construct a filename given the full path in any form.

Definition at line 371 of file filename.cpp.

References Parse().

◆ TFileName() [5/6]

owl::TFileName::TFileName ( const TFileName & src)

Constructs a filename from another filename.

Definition at line 232 of file filename.cpp.

References FormCanonicalName().

◆ TFileName() [6/6]

owl::TFileName::TFileName ( TFileName::TSpecialType type)

Construct a filename representing a special file or directory.

The parameter type can be specified from TSpecialType.

Todo
Looks like not all the types are implemented or work correctly. Need to research

Definition at line 383 of file filename.cpp.

References _T, _tcscat, BootDir, ComputerName, CurrentDir, HomeDir, MachineDir, Parse(), SharedDir, SysDir, TempDir, TempFile, and WIN95_LONGFILENAME_MAX.

Member Function Documentation

◆ AddSubDir()

TFileName & owl::TFileName::AddSubDir ( const tstring & subdir)

Definition at line 962 of file filename.cpp.

References _tcschr, FormCanonicalName(), and PathStr.

◆ Canonical()

const tstring & owl::TFileName::Canonical ( bool forceUNC = false) const

Return normal fully qualified path string.

Convert a possibly logical drive based name to a UNC name if indicated.

Definition at line 520 of file filename.cpp.

References FullCanonicalName.

◆ CanonicalStr()

const tchar * owl::TFileName::CanonicalStr ( bool forceUNC = false) const
inline

Definition at line 252 of file filename.h.

References Canonical().

◆ ChangeDir()

int owl::TFileName::ChangeDir ( ) const

Changes the current directory to the directory associated with this filename.

Returns a non-zero value on success. Call LastError for extended information.

Definition at line 956 of file filename.cpp.

References CanonicalStr().

◆ Copy()

bool owl::TFileName::Copy ( const TFileName & newName,
bool failIfExists ) const

Copy the file associated with this filename to a new file.

If failIfExists is true, the copy will not take place if a file newName already exists.

Definition at line 934 of file filename.cpp.

References CanonicalStr().

◆ CreateDir()

int owl::TFileName::CreateDir ( ) const

Creates the directory associated with this filename.

Returns a non-zero value on success. Call LastError for extended information.

Definition at line 945 of file filename.cpp.

References CanonicalStr().

◆ Exists()

bool owl::TFileName::Exists ( ) const

Determines whether the device, directory, or file exists.

Definition at line 735 of file filename.cpp.

References _USES_CONVERSION, _W2A, Canonical(), and CanonicalStr().

◆ FormCanonicalName()

void owl::TFileName::FormCanonicalName ( )

◆ GetFullFileName()

tchar * owl::TFileName::GetFullFileName ( )

Definition at line 482 of file filename.cpp.

References CanonicalStr().

◆ GetFullFileNameNoExt()

tchar * owl::TFileName::GetFullFileNameNoExt ( )

Definition at line 535 of file filename.cpp.

References Device, File, GetParts(), Path, and Server.

◆ GetNameAndExt()

tchar * owl::TFileName::GetNameAndExt ( ) const

Definition at line 530 of file filename.cpp.

References Ext, File, and GetParts().

◆ GetNameNoExt()

tchar * owl::TFileName::GetNameNoExt ( )

Definition at line 525 of file filename.cpp.

References File, and GetParts().

◆ GetParts()

const tchar * owl::TFileName::GetParts ( uint p) const

Reassembles any logical subset of filename parts.

More than one part can be checked for by bitwise oring in the parameter p. See TFileName::TPart.

Definition at line 759 of file filename.cpp.

References _tcscat, Device, DeviceStr, Ext, ExtStr, File, FileStr, NameBuffer, Path, PathStr, Server, ServerStr, and Unc.

◆ GetStatus()

int owl::TFileName::GetStatus ( TFileStatus & status) const

Get the file status struct for the item associated with this filename.

Definition at line 1012 of file filename.cpp.

References _tcscpy, Canonical(), and owl::TFileStatus::fullName.

◆ HasParts()

bool owl::TFileName::HasParts ( uint p) const

Returns true if any of the parts specified by p are used.

More than one part can be checked for by bitwise oring in the parameter p. See TFileName::TPart.

Definition at line 810 of file filename.cpp.

References Device, DeviceStr, Ext, ExtStr, File, FileStr, Path, PathStr, Server, and ServerStr.

◆ IsUNC()

bool owl::TFileName::IsUNC ( ) const
inline

Determines whether the name is UNC format as opposed to a logical-drive based machine.

Definition at line 247 of file filename.h.

References Unc.

◆ IsValid()

bool owl::TFileName::IsValid ( ) const

Determines whether a filename is valid.

Definition at line 723 of file filename.cpp.

References _USES_CONVERSION, _W2A, and CanonicalStr().

◆ MergeParts()

TFileName & owl::TFileName::MergeParts ( uint p,
const TFileName & source )

Replaces the specified parts in this with the parts from source.

More than one part can be merged by bitwise oring in the parameter p. See TFileName::TPart.

Definition at line 853 of file filename.cpp.

References Device, DeviceStr, Ext, ExtStr, File, FileStr, FormCanonicalName(), Path, PathStr, Server, and ServerStr.

◆ Move()

bool owl::TFileName::Move ( const TFileName & newName,
uint32 how = CopyAllowed )

Move (rename) the file associated with this filename, and change this name to the new name.

Under WinNT how is used to specifie how the file is to be copied:

  • ReplaceExisting = 1
  • CopyAllowed = 2
  • DelayUntilReboot = 4

Definition at line 917 of file filename.cpp.

References CanonicalStr().

◆ operator=() [1/3]

TFileName & owl::TFileName::operator= ( const TFileName & src)

Assigns new filename or freeform to this name.

Definition at line 451 of file filename.cpp.

References DeviceStr, ExtStr, FileStr, FormCanonicalName(), PathStr, ServerStr, and Unc.

◆ operator=() [2/3]

TFileName & owl::TFileName::operator= ( const tstring & src)
inline

Assigns new filename or freeform to this name.

Definition at line 226 of file filename.h.

References Parse().

◆ operator=() [3/3]

TFileName & owl::TFileName::operator= ( LPCTSTR src)
inline

Assigns new filename or freeform to this name.

Definition at line 233 of file filename.h.

References Parse().

◆ operator==()

bool owl::TFileName::operator== ( const TFileName & other) const
inline

Returns true if this filename is canonically equal to other.

Definition at line 240 of file filename.h.

References _tcsicmp, and CanonicalStr().

◆ Parse()

void owl::TFileName::Parse ( LPCTSTR freeform,
bool pathOnly = false )
protected

Parses the freeform string into the filename parts.

Definition at line 283 of file filename.cpp.

References _T, DeviceStr, ExtStr, FileStr, FormCanonicalName(), PathStr, owl::serverNamePrefixLen, ServerStr, and Unc.

◆ Remove()

bool owl::TFileName::Remove ( ) const

Deletes this file associated with this name if possible; otherwise attempts to delete the directory associated with this name (which must be empty).

Definition at line 899 of file filename.cpp.

References CanonicalStr().

◆ SetPart()

TFileName & owl::TFileName::SetPart ( uint p,
const tstring & partStr )

Replaces the specified filename parts with parts extracted from partStr.

More than one part can be checked for by bitwise oring in the parameter p. See TFileName::TPart.

Definition at line 831 of file filename.cpp.

References Device, DeviceStr, Ext, ExtStr, File, FileStr, FormCanonicalName(), Path, PathStr, Server, and ServerStr.

◆ SetStatus()

int owl::TFileName::SetStatus ( const TFileStatus & status)

◆ ShortName()

const tchar * owl::TFileName::ShortName ( bool forceUNC = false) const

Returns the short file path.

Convert a possibly logical drive based name to a UNC name if indicated.

Definition at line 547 of file filename.cpp.

References _tcscpy, CanonicalStr(), NameBuffer, and WIN95_LONGFILENAME_MAX.

◆ Squeezed()

const tchar * owl::TFileName::Squeezed ( int maxLen,
bool keepName = true ) const

Obtains a human-readable form of the filename.

The name length is at most maxLen characters.

maxLen b Result
------ - ---------
4 F T...
5 F TE...
6 F TES...
7 F TESW...
4- 7 T TESWIN.C
8-14 x TESWIN.C
15-16 x C:\...\TESWIN.C
17-23 x C:\MYAPP\...\TESWIN.C
24-25 x C:\MYAPP\...\C\TESWIN.C

Definition at line 682 of file filename.cpp.

References _MAX_PATH, _T, _tcscpy, CHECK, Device, GetParts(), NameBuffer, PathStr, Server, and Title().

◆ StripParts()

TFileName & owl::TFileName::StripParts ( uint p)

Removes the specified filename parts from this set of parts.

More than one part can be checked for by bitwise oring in the parameter p. See TFileName::TPart.

Definition at line 877 of file filename.cpp.

References _T, Device, DeviceStr, Ext, ExtStr, File, FileStr, FormCanonicalName(), Path, PathStr, Server, and ServerStr.

◆ Title()

const tchar * owl::TFileName::Title ( ) const

The Title member function uses system conventions to get a human-readable rendering of the filename appropriate for use in titles.

Note
Returns null string for directory names or malformed names. For directories, try Canonical() instead.

Definition at line 563 of file filename.cpp.

References _T, _tcscpy, Canonical(), COUNTOF, NameBuffer, and WIN95_LONGFILENAME_MAX.

◆ WildName()

static LPCTSTR owl::TFileName::WildName ( )
inlinestatic

General wildstring.

Definition at line 174 of file filename.h.

References _T.

◆ WildPart()

static LPCTSTR owl::TFileName::WildPart ( uint )
inlinestatic

Part specific?

Definition at line 175 of file filename.h.

References _T.

Member Data Documentation

◆ DeviceStr

tstring owl::TFileName::DeviceStr
protected

Holds the device filename part.

Definition at line 45 of file filename.h.

◆ ExtStr

tstring owl::TFileName::ExtStr
protected

Holds the extension filename part.

Definition at line 54 of file filename.h.

◆ FileStr

tstring owl::TFileName::FileStr
protected

Holds the file filename part (no extension).

Definition at line 51 of file filename.h.

◆ FullCanonicalName

tstring owl::TFileName::FullCanonicalName
protected

Definition at line 56 of file filename.h.

◆ NameBuffer

tchar owl::TFileName::NameBuffer[_MAX_PATH]
mutableprotected

Definition at line 57 of file filename.h.

◆ PathStr

tstring owl::TFileName::PathStr
mutableprotected

Holds the path filename part.

Definition at line 48 of file filename.h.

◆ ServerStr

tstring owl::TFileName::ServerStr
protected

Holds the server filename part.

Definition at line 42 of file filename.h.

◆ Unc

bool owl::TFileName::Unc
protected

true if UNC naming convention in use; false otherwise.

Definition at line 60 of file filename.h.


The documentation for this class was generated from the following files: