Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Filename Class Reference

The name of a file, such as a texture file or an Egg file. Stores the full pathname, and includes functions for extracting out the directory prefix part and the file extension and stuff. More...

Public Types

enum  Type { T_general = 0, T_dso = 1, T_executable = 2 }
 

Public Member Functions

 __init__ (const Filename copy)
 
 __init__ (const Filename dirname, const Filename basename)
 
 __init__ (str filename)
 
 __init__ (str filename)
 
bool __nonzero__ ()
 Returns true if the Filename is valid (not empty), or false if it is an empty string. More...
 
object __reduce__ ()
 
object __repr__ ()
 
bool chdir ()
 
int compareTimestamps (const Filename other, bool this_missing_is_old, bool other_missing_is_old)
 
int compareTo (const Filename other)
 
bool copyTo (const Filename other)
 
str cStr ()
 
bool empty ()
 
bool exists ()
 
 extractComponents (VectorString components)
 
int findOnSearchpath (const DSearchPath searchpath)
 
time_t getAccessTimestamp ()
 
str getBasename ()
 Returns the basename part of the filename. This is everything in the filename after the rightmost slash, including any extensions. More...
 
str getBasenameWoExtension ()
 Returns the basename part of the filename, without the file extension. More...
 
str getDirname ()
 Returns the directory part of the filename. This is everything in the filename up to, but not including the rightmost slash. More...
 
str getExtension ()
 Returns the file extension. This is everything after the rightmost dot, if there is one, or the empty string if there is not. More...
 
Filename getFilenameIndex (int index)
 
Streamsize getFileSize ()
 
str getFullpath ()
 Returns the entire filename: directory, basename, extension. This is the same thing returned by the string typecast operator. More...
 
str getFullpathW ()
 Returns the entire filename as a wide-character string. More...
 
str getFullpathWoExtension ()
 Returns the full filename–directory and basename parts–except for the extension. More...
 
int getHash ()
 
str getHashToEnd ()
 Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end of the filename. More...
 
bool getPattern ()
 Returns the flag indicating whether this is a filename pattern. See set_pattern(). More...
 
time_t getTimestamp ()
 
Filename::Type getType ()
 Returns the type of the file represented by the filename, as previously set by set_type(). More...
 
bool hasHash ()
 Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was called), and the filename pattern did include a sequence of hash marks, or false if it was not a filename pattern or did not include hash marks. If this is true, then get_filename_index() will return a different filename each time. More...
 
bool isBinary ()
 Returns true if the Filename has been indicated to represent a binary file via a previous call to set_binary(). It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called. More...
 
bool isBinaryOrText ()
 Returns true either is_binary() or is_text() is true; that is, that the filename has been specified as either binary or text. If this is false, the filename has not been specified. More...
 
bool isDirectory ()
 
bool isExecutable ()
 
bool isFullyQualified ()
 Returns true if the filename is fully qualified, e.g. begins with a slash. This is almost, but not quite, the same thing as !is_local(). It's not exactly the same because a special case is made for filenames that begin with a single dot followed by a slash–these are considered to be fully qualified (they are explicitly relative to the current directory, and do not refer to a filename on a search path somewhere). More...
 
bool isLocal ()
 Returns true if the filename is local, e.g. does not begin with a slash, or false if the filename is fully specified from the root. More...
 
bool isRegularFile ()
 
bool isText ()
 Returns true if the Filename has been indicated to represent a text file via a previous call to set_text(). It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called. More...
 
bool isWritable ()
 
size_t length ()
 
 makeAbsolute ()
 
 makeAbsolute (const Filename start_directory)
 
bool makeCanonical ()
 
bool makeDir ()
 
bool makeRelativeTo (Filename directory, bool allow_backups)
 
bool makeTrueCase ()
 
bool mkdir ()
 
bool openAppend (Ofstream stream)
 
bool openAppend (Pofstream stream)
 
bool openRead (Ifstream stream)
 
bool openRead (Pifstream stream)
 
bool openReadAppend (Fstream stream)
 
bool openReadAppend (Pfstream stream)
 
bool openReadWrite (Fstream stream, bool truncate)
 
bool openReadWrite (Pfstream stream, bool truncate)
 
bool openWrite (Ofstream stream, bool truncate)
 
bool openWrite (Pofstream stream, bool truncate)
 
bool operator!= (str other)
 
Filename operator+ (str other)
 
Filename operator+= (str other)
 
Filename operator/ (const Filename other)
 
bool operator< (str other)
 
Filename operator= (const Filename copy)
 
Filename operator= (str filename)
 
Filename operator= (str filename)
 
Filename operator= (str filename)
 
bool operator== (str other)
 Comparison operators are handy. More...
 
char operator[] (int n)
 
 output (Ostream out)
 
bool renameTo (const Filename other)
 
bool resolveFilename (const DSearchPath searchpath, str default_extension)
 
bool rmdir ()
 
object scanDirectory ()
 
bool scanDirectory (VectorString contents)
 
 setBasename (str s)
 
 setBasenameWoExtension (str s)
 
 setBinary ()
 Indicates that the filename represents a binary file. This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS. More...
 
 setDirname (str s)
 
 setExtension (str s)
 
 setFullpath (str s)
 You can also use any of these to reassign pieces of the filename. More...
 
 setFullpathWoExtension (str s)
 
 setHashToEnd (str s)
 
 setPattern (bool pattern)
 Sets the flag indicating whether this is a filename pattern. When this is true, the filename is understood to be a placeholder for a numbered sequence of filename, such as an image sequence. In this case, a sequence of one or more hash characters ("#") should appear in the filename string; these characters will be filled in with the corresponding number (or more) of digits representing the sequence number. Sequence numbers always begin counting at 0. More...
 
 setText ()
 Indicates that the filename represents a text file. This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS. More...
 
 setType (Filename::Type type)
 Sets the type of the file represented by the filename. This is useful for to_os_specific(), resolve_filename(), test_existence(), and all such real-world access functions. It helps the Filename know how to map the internal filename to the OS-specific filename (for instance, maybe executables should have an .exe extension). More...
 
 standardize ()
 
str substr (size_t begin, size_t end)
 
str toOsGeneric ()
 
str toOsLongName ()
 
str toOsShortName ()
 
str toOsSpecific ()
 
str toOsSpecificW ()
 
bool touch ()
 
bool unlink ()
 

Static Public Member Functions

static Filename binaryFilename (const Filename filename)
 
static Filename binaryFilename (str filename)
 
static Filename dsoFilename (str filename)
 
static Filename executableFilename (str filename)
 
static Filename expandFrom (str user_string, Filename::Type type)
 
static Filename fromOsSpecific (str os_specific, Filename::Type type)
 
static Filename fromOsSpecificW (str os_specific, Filename::Type type)
 
static TypeHandle getClassType ()
 
static const Filename getCommonAppdataDirectory ()
 
static TextEncoder::Encoding getFilesystemEncoding ()
 Specifies the default encoding to be used for all subsequent Filenames objects. See set_filesystem_encoding(). More...
 
static const Filename getHomeDirectory ()
 
static const Filename getTempDirectory ()
 
static const Filename getUserAppdataDirectory ()
 
static Filename patternFilename (str filename)
 Constructs a filename that represents a sequence of numbered files. See set_pattern(). More...
 
static setFilesystemEncoding (TextEncoder::Encoding encoding)
 Specifies the default encoding to be used for all subsequent Filenames. This is used to represent wide-character (Unicode) filenames internally. On non-Windows-based systems, the encoded filename is also passed to the underlying operating system. More...
 
static Filename temporary (str dirname, str prefix, str suffix, Filename::Type type)
 
static Filename textFilename (const Filename filename)
 
static Filename textFilename (str filename)
 

Detailed Description

The name of a file, such as a texture file or an Egg file. Stores the full pathname, and includes functions for extracting out the directory prefix part and the file extension and stuff.

A Filename is also aware of the mapping between the Unix-like filename convention we use internally, and the local OS's specific filename convention, and it knows how to perform basic OS-specific I/O, like testing for file existence and searching a searchpath, as well as the best way to open an fstream for reading or writing.

Member Enumeration Documentation

◆ Type

enum Type
Enumerator
T_general 

These type values must fit within the bits allocated for F_type, below.

T_dso 
T_executable 

Member Function Documentation

◆ __init__() [1/4]

__init__ ( const Filename  copy)

◆ __init__() [2/4]

__init__ ( const Filename  dirname,
const Filename  basename 
)

◆ __init__() [3/4]

__init__ ( str  filename)

◆ __init__() [4/4]

__init__ ( str  filename)

◆ __nonzero__()

bool __nonzero__ ( )

Returns true if the Filename is valid (not empty), or false if it is an empty string.

This implements the Python equivalent to operator bool. Defining an actual operator bool method for C++ use would work too, but it seems to cause too many ambiguities for the C++ compiler, so we use this Python-only approach instead.

◆ __reduce__()

object __reduce__ ( )

◆ __repr__()

object __repr__ ( )

◆ binaryFilename() [1/2]

static Filename binaryFilename ( const Filename  filename)
static

◆ binaryFilename() [2/2]

static Filename binaryFilename ( str  filename)
static

◆ chdir()

bool chdir ( )

◆ compareTimestamps()

int compareTimestamps ( const Filename  other,
bool  this_missing_is_old,
bool  other_missing_is_old 
)

◆ compareTo()

int compareTo ( const Filename  other)

◆ copyTo()

bool copyTo ( const Filename  other)

◆ cStr()

str cStr ( )

◆ dsoFilename()

static Filename dsoFilename ( str  filename)
static

◆ empty()

bool empty ( )

◆ executableFilename()

static Filename executableFilename ( str  filename)
static

◆ exists()

bool exists ( )

◆ expandFrom()

static Filename expandFrom ( str  user_string,
Filename::Type  type 
)
static

◆ extractComponents()

extractComponents ( VectorString  components)

◆ findOnSearchpath()

int findOnSearchpath ( const DSearchPath  searchpath)

◆ fromOsSpecific()

static Filename fromOsSpecific ( str  os_specific,
Filename::Type  type 
)
static

◆ fromOsSpecificW()

static Filename fromOsSpecificW ( str  os_specific,
Filename::Type  type 
)
static

◆ getAccessTimestamp()

time_t getAccessTimestamp ( )

◆ getBasename()

str getBasename ( )

Returns the basename part of the filename. This is everything in the filename after the rightmost slash, including any extensions.

◆ getBasenameWoExtension()

str getBasenameWoExtension ( )

Returns the basename part of the filename, without the file extension.

◆ getClassType()

static TypeHandle getClassType ( )
static

◆ getCommonAppdataDirectory()

static const Filename getCommonAppdataDirectory ( )
static

◆ getDirname()

str getDirname ( )

Returns the directory part of the filename. This is everything in the filename up to, but not including the rightmost slash.

◆ getExtension()

str getExtension ( )

Returns the file extension. This is everything after the rightmost dot, if there is one, or the empty string if there is not.

◆ getFilenameIndex()

Filename getFilenameIndex ( int  index)

◆ getFileSize()

Streamsize getFileSize ( )

◆ getFilesystemEncoding()

static TextEncoder::Encoding getFilesystemEncoding ( )
static

Specifies the default encoding to be used for all subsequent Filenames objects. See set_filesystem_encoding().

◆ getFullpath()

str getFullpath ( )

Returns the entire filename: directory, basename, extension. This is the same thing returned by the string typecast operator.

◆ getFullpathW()

str getFullpathW ( )

Returns the entire filename as a wide-character string.

◆ getFullpathWoExtension()

str getFullpathWoExtension ( )

Returns the full filename–directory and basename parts–except for the extension.

◆ getHash()

int getHash ( )

◆ getHashToEnd()

str getHashToEnd ( )

Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end of the filename.

◆ getHomeDirectory()

static const Filename getHomeDirectory ( )
static

◆ getPattern()

bool getPattern ( )

Returns the flag indicating whether this is a filename pattern. See set_pattern().

◆ getTempDirectory()

static const Filename getTempDirectory ( )
static

◆ getTimestamp()

time_t getTimestamp ( )

◆ getType()

Filename::Type getType ( )

Returns the type of the file represented by the filename, as previously set by set_type().

◆ getUserAppdataDirectory()

static const Filename getUserAppdataDirectory ( )
static

◆ hasHash()

bool hasHash ( )

Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was called), and the filename pattern did include a sequence of hash marks, or false if it was not a filename pattern or did not include hash marks. If this is true, then get_filename_index() will return a different filename each time.

◆ isBinary()

bool isBinary ( )

Returns true if the Filename has been indicated to represent a binary file via a previous call to set_binary(). It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called.

◆ isBinaryOrText()

bool isBinaryOrText ( )

Returns true either is_binary() or is_text() is true; that is, that the filename has been specified as either binary or text. If this is false, the filename has not been specified.

◆ isDirectory()

bool isDirectory ( )

◆ isExecutable()

bool isExecutable ( )

◆ isFullyQualified()

bool isFullyQualified ( )

Returns true if the filename is fully qualified, e.g. begins with a slash. This is almost, but not quite, the same thing as !is_local(). It's not exactly the same because a special case is made for filenames that begin with a single dot followed by a slash–these are considered to be fully qualified (they are explicitly relative to the current directory, and do not refer to a filename on a search path somewhere).

◆ isLocal()

bool isLocal ( )

Returns true if the filename is local, e.g. does not begin with a slash, or false if the filename is fully specified from the root.

◆ isRegularFile()

bool isRegularFile ( )

◆ isText()

bool isText ( )

Returns true if the Filename has been indicated to represent a text file via a previous call to set_text(). It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called.

◆ isWritable()

bool isWritable ( )

◆ length()

size_t length ( )

◆ makeAbsolute() [1/2]

makeAbsolute ( )

◆ makeAbsolute() [2/2]

makeAbsolute ( const Filename  start_directory)

◆ makeCanonical()

bool makeCanonical ( )

◆ makeDir()

bool makeDir ( )

◆ makeRelativeTo()

bool makeRelativeTo ( Filename  directory,
bool  allow_backups 
)

◆ makeTrueCase()

bool makeTrueCase ( )

◆ mkdir()

bool mkdir ( )

◆ openAppend() [1/2]

bool openAppend ( Ofstream  stream)

◆ openAppend() [2/2]

bool openAppend ( Pofstream  stream)

◆ openRead() [1/2]

bool openRead ( Ifstream  stream)

◆ openRead() [2/2]

bool openRead ( Pifstream  stream)

◆ openReadAppend() [1/2]

bool openReadAppend ( Fstream  stream)

◆ openReadAppend() [2/2]

bool openReadAppend ( Pfstream  stream)

◆ openReadWrite() [1/2]

bool openReadWrite ( Fstream  stream,
bool  truncate 
)

◆ openReadWrite() [2/2]

bool openReadWrite ( Pfstream  stream,
bool  truncate 
)

◆ openWrite() [1/2]

bool openWrite ( Ofstream  stream,
bool  truncate 
)

◆ openWrite() [2/2]

bool openWrite ( Pofstream  stream,
bool  truncate 
)

◆ operator!=()

bool operator!= ( str  other)

◆ operator+()

Filename operator+ ( str  other)

◆ operator+=()

Filename operator+= ( str  other)

◆ operator/()

Filename operator/ ( const Filename  other)

◆ operator<()

bool operator< ( str  other)

◆ operator=() [1/4]

Filename operator= ( const Filename  copy)

◆ operator=() [2/4]

Filename operator= ( str  filename)

◆ operator=() [3/4]

Filename operator= ( str  filename)

◆ operator=() [4/4]

Filename operator= ( str  filename)

◆ operator==()

bool operator== ( str  other)

Comparison operators are handy.

◆ operator[]()

char operator[] ( int  n)

◆ output()

output ( Ostream  out)

◆ patternFilename()

static Filename patternFilename ( str  filename)
static

Constructs a filename that represents a sequence of numbered files. See set_pattern().

◆ renameTo()

bool renameTo ( const Filename  other)

◆ resolveFilename()

bool resolveFilename ( const DSearchPath  searchpath,
str  default_extension 
)

◆ rmdir()

bool rmdir ( )

◆ scanDirectory() [1/2]

object scanDirectory ( )

◆ scanDirectory() [2/2]

bool scanDirectory ( VectorString  contents)

◆ setBasename()

setBasename ( str  s)

◆ setBasenameWoExtension()

setBasenameWoExtension ( str  s)

◆ setBinary()

setBinary ( )

Indicates that the filename represents a binary file. This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS.

◆ setDirname()

setDirname ( str  s)

◆ setExtension()

setExtension ( str  s)

◆ setFilesystemEncoding()

static setFilesystemEncoding ( TextEncoder::Encoding  encoding)
static

Specifies the default encoding to be used for all subsequent Filenames. This is used to represent wide-character (Unicode) filenames internally. On non-Windows-based systems, the encoded filename is also passed to the underlying operating system.

◆ setFullpath()

setFullpath ( str  s)

You can also use any of these to reassign pieces of the filename.

◆ setFullpathWoExtension()

setFullpathWoExtension ( str  s)

◆ setHashToEnd()

setHashToEnd ( str  s)

◆ setPattern()

setPattern ( bool  pattern)

Sets the flag indicating whether this is a filename pattern. When this is true, the filename is understood to be a placeholder for a numbered sequence of filename, such as an image sequence. In this case, a sequence of one or more hash characters ("#") should appear in the filename string; these characters will be filled in with the corresponding number (or more) of digits representing the sequence number. Sequence numbers always begin counting at 0.

When this is true, methods like has_hash() and get_hash_to_end() and get_filename_index() may be called. Methods like is_exists() will implicitly test for existance of filename sequence 0.

◆ setText()

setText ( )

Indicates that the filename represents a text file. This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS.

◆ setType()

setType ( Filename::Type  type)

Sets the type of the file represented by the filename. This is useful for to_os_specific(), resolve_filename(), test_existence(), and all such real-world access functions. It helps the Filename know how to map the internal filename to the OS-specific filename (for instance, maybe executables should have an .exe extension).

◆ standardize()

standardize ( )

◆ substr()

str substr ( size_t  begin,
size_t  end 
)

◆ temporary()

static Filename temporary ( str  dirname,
str  prefix,
str  suffix,
Filename::Type  type 
)
static

◆ textFilename() [1/2]

static Filename textFilename ( const Filename  filename)
static

◆ textFilename() [2/2]

static Filename textFilename ( str  filename)
static

◆ toOsGeneric()

str toOsGeneric ( )

◆ toOsLongName()

str toOsLongName ( )

◆ toOsShortName()

str toOsShortName ( )

◆ toOsSpecific()

str toOsSpecific ( )

◆ toOsSpecificW()

str toOsSpecificW ( )

◆ touch()

bool touch ( )

◆ unlink()

bool unlink ( )