44class EXPCL_DTOOL_DTOOLUTIL Filename {
62 INLINE Filename(
const char *filename);
63 INLINE Filename(
const std::string &filename);
64 INLINE Filename(
const std::wstring &filename);
65 INLINE Filename(
const Filename ©);
66 INLINE Filename(std::string &&filename)
noexcept;
67 INLINE Filename(Filename &&from)
noexcept;
71 Filename(
const Filename &dirname,
const Filename &basename);
74 EXTENSION(Filename(PyObject *path));
76 EXTENSION(PyObject *__reduce__(PyObject *self)
const);
82 INLINE
static Filename text_filename(
const Filename &filename);
83 INLINE
static Filename text_filename(
const std::string &filename);
84 INLINE
static Filename binary_filename(
const Filename &filename);
85 INLINE
static Filename binary_filename(
const std::string &filename);
86 INLINE
static Filename dso_filename(
const std::string &filename);
87 INLINE
static Filename executable_filename(
const std::string &filename);
92 Type type = T_general);
94 Type type = T_general);
95 static Filename
expand_from(
const std::string &user_string,
96 Type type = T_general);
97 static Filename
temporary(
const std::string &dirname,
const std::string &prefix,
98 const std::string &suffix = std::string(),
99 Type type = T_general);
107 INLINE Filename &operator = (
const std::string &filename);
108 INLINE Filename &operator = (
const std::wstring &filename);
109 INLINE Filename &operator = (
const char *filename);
110 INLINE Filename &operator = (
const Filename ©);
111 INLINE Filename &operator = (std::string &&filename)
noexcept;
112 INLINE Filename &operator = (Filename &&from)
noexcept;
115 INLINE
operator const std::string & ()
const;
116 INLINE
const char *c_str()
const;
117 INLINE
bool empty()
const;
118 INLINE
size_t length()
const;
119 INLINE
char operator [] (
size_t n)
const;
121 EXTENSION(PyObject *__repr__()
const);
122 EXTENSION(PyObject *__fspath__()
const);
124 INLINE std::string substr(
size_t begin)
const;
125 INLINE std::string substr(
size_t begin,
size_t end)
const;
126 INLINE
void operator += (
const std::string &other);
127 INLINE Filename operator + (
const std::string &other)
const;
129 INLINE Filename operator / (
const Filename &other)
const;
130 EXTENSION(Filename __truediv__(
const Filename &other)
const);
196 bool this_missing_is_old =
true,
197 bool other_missing_is_old =
true)
const;
203 const std::string &default_extension = std::string());
212 bool open_read(std::ifstream &stream)
const;
213 bool open_write(std::ofstream &stream,
bool truncate =
true)
const;
215 bool open_read_write(std::fstream &stream,
bool truncate =
false)
const;
218#ifdef USE_PANDAFILESTREAM
220 bool open_write(pofstream &stream,
bool truncate =
true)
const;
229 BLOCKING
bool rename_to(
const Filename &other)
const;
230 BLOCKING
bool copy_to(
const Filename &other)
const;
237 INLINE
bool operator == (
const std::string &other)
const;
238 INLINE
bool operator != (
const std::string &other)
const;
239 INLINE
bool operator < (
const std::string &other)
const;
240 INLINE
int compare_to(
const Filename &other)
const;
244 INLINE
void output(std::ostream &out)
const;
254 void locate_basename();
255 void locate_extension();
257 size_t get_common_prefix(
const std::string &other)
const;
258 static int count_slashes(
const std::string &str);
259 bool r_make_canonical(
const Filename &cwd);
261 std::string _filename;
265 size_t _basename_start;
266 size_t _basename_end;
267 size_t _extension_start;
273 static TextEncoder::Encoding _filesystem_encoding;
274 static TVOLATILE AtomicAdjust::Pointer _home_directory;
275 static TVOLATILE AtomicAdjust::Pointer _temp_directory;
276 static TVOLATILE AtomicAdjust::Pointer _user_appdata_directory;
277 static TVOLATILE AtomicAdjust::Pointer _common_appdata_directory;
281 static std::string _internal_data_dir;
288 static void init_type() {
296INLINE std::ostream &operator << (std::ostream &out,
const Filename &n) {
This class stores a list of directories that can be searched, in order, to locate a particular file.
The name of a file, such as a texture file or an Egg file.
bool __nonzero__() const
Returns true if the Filename is valid (not empty), or false if it is an empty string.
void set_basename(const std::string &s)
Replaces the basename part of the filename.
int compare_timestamps(const Filename &other, bool this_missing_is_old=true, bool other_missing_is_old=true) const
Returns a number less than zero if the file named by this object is older than the given file,...
bool open_append(std::ofstream &stream) const
Opens the indicated ofstream for writing the file, if possible.
bool is_regular_file() const
Returns true if the filename exists on the physical disk and is the name of a regular file (i....
bool scan_directory(vector_string &contents) const
Attempts to open the named filename as if it were a directory and looks for the non-hidden files with...
void set_type(Type type)
Sets the type of the file represented by the filename.
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
bool copy_to(const Filename &other) const
Copies the file to the indicated new filename, by reading the contents and writing it to the new file...
std::string get_basename() const
Returns the basename part of the filename.
bool resolve_filename(const DSearchPath &searchpath, const std::string &default_extension=std::string())
Searches the given search path for the filename.
Filename get_filename_index(int index) const
If the pattern flag is set for this Filename and the filename string actually includes a sequence of ...
bool open_read_append(std::fstream &stream) const
Opens the indicated ifstream for reading and writing the file, if possible; writes are appended to th...
bool has_hash() const
Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was ca...
bool is_executable() const
Returns true if the filename exists and is executable.
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
bool is_text() const
Returns true if the Filename has been indicated to represent a text file via a previous call to set_t...
std::string to_os_short_name() const
This works like to_os_generic(), but it returns the "short name" version of the filename,...
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
static const Filename & get_home_directory()
Returns a path to the user's home directory, if such a thing makes sense in the current OS,...
bool rmdir() const
The inverse of mkdir(): this removes the directory named by this Filename, if it is in fact a directo...
bool rename_to(const Filename &other) const
Renames the file to the indicated new filename.
bool open_read_write(std::fstream &stream, bool truncate=false) const
Opens the indicated fstream for read/write access to the file, if possible.
bool is_binary() const
Returns true if the Filename has been indicated to represent a binary file via a previous call to set...
void set_hash_to_end(const std::string &s)
Replaces the part of the filename from the beginning of the hash sequence to the end of the filename.
int get_hash() const
Returns a hash code that attempts to be mostly unique for different Filenames.
static const Filename & get_common_appdata_directory()
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing appl...
static Filename from_os_specific_w(const std::wstring &os_specific, Type type=T_general)
The wide-string variant of from_os_specific().
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
static Filename expand_from(const std::string &user_string, Type type=T_general)
Returns the same thing as from_os_specific(), but embedded environment variable references (e....
void standardize()
Converts the filename to standard form by replacing consecutive slashes with a single slash,...
void set_dirname(const std::string &s)
Replaces the directory part of the filename.
void set_fullpath_wo_extension(const std::string &s)
Replaces the full filename–directory and basename parts–except for the extension.
bool is_writable() const
Returns true if the filename exists on the physical disk and is either a directory or a regular file ...
void set_binary()
Indicates that the filename represents a binary file.
bool is_binary_or_text() const
Returns true either is_binary() or is_text() is true; that is, that the filename has been specified a...
void set_basename_wo_extension(const std::string &s)
Replaces the basename part of the filename, without the file extension.
static TextEncoder::Encoding get_filesystem_encoding()
Specifies the default encoding to be used for all subsequent Filenames objects.
static const Filename & get_temp_directory()
Returns a path to a system-defined temporary directory.
static const Filename & get_user_appdata_directory()
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing appl...
bool chdir() const
Changes directory to the specified location.
bool touch() const
Updates the modification time of the file to the current time.
std::wstring to_os_specific_w() const
The wide-string variant on to_os_specific().
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
bool get_pattern() const
Returns the flag indicating whether this is a filename pattern.
bool make_true_case()
On a case-insensitive operating system (e.g.
static void set_filesystem_encoding(TextEncoder::Encoding encoding)
Specifies the default encoding to be used for all subsequent Filenames.
void set_text()
Indicates that the filename represents a text file.
time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
static Filename temporary(const std::string &dirname, const std::string &prefix, const std::string &suffix=std::string(), Type type=T_general)
Generates a temporary filename within the indicated directory, using the indicated prefix.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
std::string get_hash_to_end() const
Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end o...
void set_extension(const std::string &s)
Replaces the file extension.
std::string to_os_generic() const
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood...
int find_on_searchpath(const DSearchPath &searchpath)
Performs the reverse of the resolve_filename() operation: assuming that the current filename is fully...
void extract_components(vector_string &components) const
Extracts out the individual directory components of the path into a series of strings.
bool is_directory() const
Returns true if the filename exists on the physical disk and is a directory name, false otherwise.
std::string to_os_long_name() const
This is the opposite of to_os_short_name(): it returns the "long name" of the filename,...
bool atomic_compare_and_exchange_contents(std::string &orig_contents, const std::string &old_contents, const std::string &new_contents) const
Uses native file-locking mechanisms to atomically replace the contents of a (small) file with the spe...
std::wstring get_fullpath_w() const
Returns the entire filename as a wide-character string.
bool atomic_read_contents(std::string &contents) const
Uses native file-locking mechanisms to atomically read the contents of a (small) file.
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
bool make_relative_to(Filename directory, bool allow_backups=true)
Adjusts this filename, which must be a fully-specified pathname beginning with a slash,...
std::string get_extension() const
Returns the file extension.
void set_fullpath(const std::string &s)
Replaces the entire filename: directory, basename, extension.
bool mkdir() const
Creates the directory named by this filename.
bool is_local() const
Returns true if the filename is local, e.g.
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
std::string get_dirname() const
Returns the directory part of the filename.
void make_absolute()
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname),...
Type get_type() const
Returns the type of the file represented by the filename, as previously set by set_type().
static Filename pattern_filename(const std::string &filename)
Constructs a filename that represents a sequence of numbered files.
void set_pattern(bool pattern)
Sets the flag indicating whether this is a filename pattern.
bool exists() const
Returns true if the filename exists on the physical disk, false otherwise.
time_t get_access_timestamp() const
Returns a time_t value that represents the time the file was last accessed, if this information is av...
std::streamsize get_file_size() const
Returns the size of the file in bytes, or 0 if there is an error.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.