# panda3d.core.VirtualFile¶

class VirtualFile

The abstract base class for a file or directory within the VirtualFileSystem.

Inheritance diagram

closeReadFile(stream: istream) → None

Closes a file opened by a previous call to openReadFile(). This really just deletes the istream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.

closeReadWriteFile(stream: iostream) → None

Closes a file opened by a previous call to openReadWriteFile(). This really just deletes the iostream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.

closeWriteFile(stream: ostream) → None

Closes a file opened by a previous call to openWriteFile(). This really just deletes the ostream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.

copyFile(new_file: VirtualFile) → bool

Attempts to copy the contents of this file to the indicated file. Returns true on success, false on failure.

deleteFile() → bool

Attempts to delete this file or directory. This can remove a single file or an empty directory. It will not remove a nonempty directory. Returns true on success, false on failure.

static getClassType() → TypeHandle
Return type

TypeHandle

getFileSize() → streamsize

Returns the current size on disk (or wherever it is) of the file before it has been opened.

Return type

streamsize

getFileSize(stream: istream) → streamsize

Returns the current size on disk (or wherever it is) of the already-open file. Pass in the stream that was returned by openReadFile(); some implementations may require this stream to determine the size.

Return type

streamsize

getFileSystem() → VirtualFileSystem
Return type

VirtualFileSystem

getFilename() → Filename
Return type

Filename

getOriginalFilename() → Filename

Returns the original filename as it was used to locate this VirtualFile. This is usually, but not always, the same string returned by getFilename().

Return type

Filename

getSystemInfo(info: SubfileInfo) → bool

Populates the SubfileInfo structure with the data representing where the file actually resides on disk, if this is knowable. Returns true if the file might reside on disk, and the info is populated, or false if it does not (or it is not known where the file resides), in which case the info is meaningless.

getTimestamp() → time_t

Returns a time_t value that represents the time the file was last modified, to within whatever precision the operating system records this information (on a Windows95 system, for instance, this may only be accurate to within 2 seconds).

If the timestamp cannot be determined, either because it is not supported by the operating system or because there is some error (such as file not found), returns 0.

Return type

time_t

hasFile() → bool

Returns true if this file exists, false otherwise.

isDirectory() → bool

Returns true if this file represents a directory (and scanDirectory() may be called), false otherwise.

isRegularFile() → bool

Returns true if this file represents a regular file (and readFile() may be called), false otherwise.

isWritable() → bool

Returns true if this file may be written to, which implies writeFile() may be called (unless it is a directory instead of a regular file).

ls(out: ostream) → None

If the file represents a directory, lists its contents.

lsAll(out: ostream) → None

If the file represents a directory, recursively lists its contents and those of all subdirectories.

openAppendFile() → ostream

Works like openWriteFile(), but the file is opened in append mode. Like open_write_file, the returned pointer should eventually be passed to closeWriteFile().

Return type

ostream

openReadAppendFile() → iostream

Works like openReadWriteFile(), but the file is opened in append mode. Like open_read_write_file, the returned pointer should eventually be passed to closeReadWriteFile().

Return type

iostream

openReadFile(auto_unwrap: bool) → istream

Opens the file for reading. Returns a newly allocated istream on success (which you should eventually delete when you are done reading). Returns NULL on failure.

Return type

istream

openReadWriteFile(truncate: bool) → iostream

Opens the file for writing. Returns a newly allocated iostream on success (which you should eventually delete when you are done writing). Returns NULL on failure.

Return type

iostream

openWriteFile(auto_wrap: bool, truncate: bool) → ostream

Opens the file for writing. Returns a newly allocated ostream on success (which you should eventually delete when you are done writing). Returns NULL on failure.

Return type

ostream

output(out: ostream) → None
readFile(auto_unwrap: bool) → object

Returns the entire contents of the file as a string.

renameFile(new_file: VirtualFile) → bool

Attempts to move or rename this file or directory. If the original file is an ordinary file, it will quietly replace any already-existing file in the new filename (but not a directory). If the original file is a directory, the new filename must not already exist.

If the file is a directory, the new filename must be within the same mount point. If the file is an ordinary file, the new filename may be anywhere; but if it is not within the same mount point then the rename operation is automatically performed as a two-step copy-and-delete operation.

scanDirectory() → VirtualFileList

If the file represents a directory (that is, isDirectory() returns true), this returns the list of files within the directory at the current time. Returns NULL if the file is not a directory or if the directory cannot be read.

Return type

VirtualFileList

wasReadSuccessful() → bool

Call this method after a reading the istream returned by openReadFile() to completion. If it returns true, the file was read completely and without error; if it returns false, there may have been some errors or a truncated file read. This is particularly likely if the stream is a VirtualFileHTTP.

writeFile(data: object, auto_wrap: bool) → object