# VirtualFileSystem

from pandac.PandaModules import VirtualFileSystem

Class : VirtualFileSystem
Description : A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
For instance, a VirtualFileSystem can transparently mount one or more Multifiles as their own subdirectory hierarchies.

## Inheritance:

VirtualFileSystem:

## Methods of VirtualFileSystem:

chdir
closeReadFile
exists
findAllFiles
findFile
getCwd
getFile
getGlobalPtr
isDirectory
isRegularFile
ls
lsAll
mount
openReadFile
readFile
resolveFilename
unmount
unmountAll
unmountPoint
write

## Constants in VirtualFileSystem:

MFOwnsPointer | (MountFlags)
MFReadOnly | (MountFlags)

chdir bool VirtualFileSystem::chdir(string const &new_directory); Description: Changes the current directory. This is used to resolve relative pathnames in get_file() and/or find_file(). Returns true if successful, false otherwise. This accepts a string rather than a Filename simply for programmer convenience from the Python prompt.

closeReadFile void VirtualFileSystem::close_read_file(istream *stream) const; Description: Closes a file opened by a previous call to open_read_file(). 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.

exists bool VirtualFileSystem::exists(Filename const &filename) const; Filename: virtualFileSystem.I Created by: drose (03Aug02) PANDA 3D SOFTWARE Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved All use of this software is subject to the terms of the Panda 3d Software license. You should have received a copy of this license along with this source code; you will also find a current copy of the license at http://etc.cmu.edu/panda3d/docs/license/ . To contact the maintainers of this program write to panda3d-general@lists.sourceforge.net . Description: Convenience function; returns true if the named file exists.

findAllFiles int VirtualFileSystem::find_all_files(Filename const &filename, DSearchPath const &searchpath, DSearchPath::Results &results) const; Description: Searches all the directories in the search list for the indicated file, in order. Fills up the results list with *all* of the matching filenames found, if any. Returns the number of matches found. It is the responsibility of the the caller to clear the results list first; otherwise, the newly-found files will be appended to the list.

findFile PointerTo< VirtualFile > VirtualFileSystem::find_file(Filename const &filename, DSearchPath const &searchpath) const; Description: Uses the indicated search path to find the file within the file system. Returns the first occurrence of the file found, or NULL if the file cannot be found.

getCwd Filename const &VirtualFileSystem::get_cwd(void) const; Description: Returns the current directory name. See chdir().

getFile PointerTo< VirtualFile > VirtualFileSystem::get_file(Filename const &filename) const; Description: Looks up the file by the indicated name in the file system. Returns a VirtualFile pointer representing the file if it is found, or NULL if it is not.

getGlobalPtr static VirtualFileSystem *VirtualFileSystem::get_global_ptr(void); Description: Returns the default global VirtualFileSystem. You may create your own personal VirtualFileSystem objects and use them for whatever you like, but Panda will attempt to load models and stuff from this default object. Initially, the global VirtualFileSystem is set up to mount the OS filesystem to root; i.e. it is equivalent to the OS filesystem. This may be subsequently adjusted by the user.

isDirectory bool VirtualFileSystem::is_directory(Filename const &filename) const; Description: Convenience function; returns true if the named file exists and is a directory.

isRegularFile bool VirtualFileSystem::is_regular_file(Filename const &filename) const; Description: Convenience function; returns true if the named file exists and is a regular file.

ls void VirtualFileSystem::ls(string const &filename) const; Description: Convenience function; lists the files within the indicated directory. This accepts a string instead of a Filename purely for programmer convenience at the Python prompt.

lsAll void VirtualFileSystem::ls_all(string const &filename) const; Description: Convenience function; lists the files within the indicated directory, and all files below, recursively. This accepts a string instead of a Filename purely for programmer convenience at the Python prompt.

mount bool VirtualFileSystem::mount(Multifile *multifile, string const &mount_point, int flags); Description: Mounts the indicated Multifile at the given mount point. Description: Mounts the indicated system file or directory at the given mount point. If the named file is a directory, mounts the directory. If the named file is a Multifile, mounts it as a Multifile. Returns true on success, false on failure. A given system directory may be mounted to multiple different mount point, and the same mount point may share multiple system directories. In the case of ambiguities (that is, two different files with exactly the same full pathname), the most-recently mounted system wins. Note that a mounted VirtualFileSystem directory is fully case-sensitive, unlike the native Windows file system, so you must refer to files within the virtual file system with exactly the right case.

openReadFile istream *VirtualFileSystem::open_read_file(Filename const &filename, bool auto_unwrap) const; Description: Convenience function; returns a newly allocated istream if the file exists and can be read, or NULL otherwise. Does not return an invalid istream. If auto_unwrap is true, an explicitly-named .pz file is automatically decompressed and the decompressed contents are returned. This is different than vfs-implicit-pz, which will automatically decompress a file if the extension .pz is *not* given.

readFile string VirtualFileSystem::read_file(Filename const &filename, bool auto_unwrap) const; Description: Convenience function; returns the entire contents of the indicated file as a string. If auto_unwrap is true, an explicitly-named .pz file is automatically decompressed and the decompressed contents are returned. This is different than vfs-implicit-pz, which will automatically decompress a file if the extension .pz is *not* given. Description: Convenience function; fills the string up with the data from the indicated file, if it exists and can be read. Returns true on success, false otherwise. Description: Convenience function; fills the pvector up with the data from the indicated file, if it exists and can be read. Returns true on success, false otherwise.

resolveFilename bool VirtualFileSystem::resolve_filename(Filename &filename, DSearchPath const &searchpath, string const &default_extension = ((string()))) const; Description: Searches the given search path for the filename. If it is found, updates the filename to the full pathname found and returns true; otherwise, returns false.

unmount int VirtualFileSystem::unmount(Multifile *multifile); Description: Unmounts all appearances of the indicated Multifile from the file system. Returns the number of appearances unmounted. Description: Unmounts all appearances of the indicated physical filename (either a directory name or a Multifile name) from the file system. Returns the number of appearances unmounted.

unmountAll int VirtualFileSystem::unmount_all(void); Description: Unmounts all files from the file system. Returns the number of systems unmounted.

unmountPoint int VirtualFileSystem::unmount_point(string const &mount_point); Description: Unmounts all systems attached to the given mount point from the file system. Returns the number of appearances unmounted.

write void VirtualFileSystem::write(ostream &out) const; Description: Print debugging information. (e.g. from Python or gdb prompt).