The following methods are required for a minimal Filesystem interface:
The following methods are required for a minimal Filesystem interface:
* `open` Opens a file for read/writing
* :meth:`~fs.base.FS.open` Opens a file for read/writing
* `isfile` Check wether the path exists and is a file
* :meth:`~fs.base.FS.isfile` Check wether the path exists and is a file
* `isdir` Check wether a path exists and is a directory
* :meth:`~fs.base.FS.isdir` Check wether a path exists and is a directory
* `listdir` List the contents of a directory
* :meth:`~fs.base.FS.listdir` List the contents of a directory
* `makedir` Create a new directory
* :meth:`~fs.base.FS.makedir` Create a new directory
* `remove` Remove an existing file
* :meth:`~fs.base.FS.remove` Remove an existing file
* `removedir` Remove an existing directory
* :meth:`~fs.base.FS.removedir` Remove an existing directory
* `rename` Automically rename a file or directory
* :meth:`~fs.base.FS.rename` Automically rename a file or directory
* `getinfo` Return information about the path e.h. size, mtime
* :meth:`~fs.base.FS.getinfo` Return information about the path e.h. size, mtime
Non - Essential Methods
Non - Essential Methods
...
@@ -25,16 +25,16 @@ Non - Essential Methods
...
@@ -25,16 +25,16 @@ Non - Essential Methods
The following methods have default implementations in fs.base.FS and aren't required for a functional FS interface. They may be overriden if an alternative implementation can be supplied:
The following methods have default implementations in fs.base.FS and aren't required for a functional FS interface. They may be overriden if an alternative implementation can be supplied:
* `copy` Copy a file to a new location
* :meth:`~fs.base.FS.copy` Copy a file to a new location
* `copydir` Recursively copy a directory to a new location
* :meth:`~fs.base.FS.copydir` Recursively copy a directory to a new location
* `desc` Return a short destriptive text regarding a path
* :meth:`~fs.base.FS.desc` Return a short destriptive text regarding a path
* `exists` Check whether a path exists as file or directory
* :meth:`~fs.base.FS.exists` Check whether a path exists as file or directory
* `getsyspath` Get a file's name in the local filesystem, if possible
* :meth:`~fs.base.FS.getsyspath` Get a file's name in the local filesystem, if possible
* `hassyspath` Check if a path maps to a system path (recognised by the OS)
* :meth:`~fs.base.FS.hassyspath` Check if a path maps to a system path (recognised by the OS)
* `move` Move a file to a new location
* :meth:`~fs.base.FS.move` Move a file to a new location
* `movedir` Recursively move a directory to a new location
* :meth:`~fs.base.FS.movedir` Recursively move a directory to a new location
* `opendir` Opens a directory and returns an FS object that represents it
* :meth:`~fs.base.FS.opendir` Opens a directory and returns an FS object that represents it
* `safeopen` Like `open` but returns a NullFile if the file could not be opened
* :meth:`~fs.base.FS.safeopen` Like :meth:`~fs.base.open` but returns a NullFile if the file could not be opened
Utility Methods
Utility Methods
...
@@ -42,11 +42,12 @@ Utility Methods
...
@@ -42,11 +42,12 @@ Utility Methods
The following members have implementations in fs.base.FS but will probably never need a non-default implementation, although there is nothing to prevent a derived class from implementing these:
The following members have implementations in fs.base.FS but will probably never need a non-default implementation, although there is nothing to prevent a derived class from implementing these:
* `createfile` Create a file with data
* :meth:`~fs.base.FS.createfile` Create a file with data
* `getcontents` Returns the contents of a file as a string
* :meth:`~fs.base.FS.getcontents` Returns the contents of a file as a string
* `getsize` Returns the number of bytes used for a given file or directory
* :meth:`~fs.base.FS.getsize` Returns the number of bytes used for a given file or directory
* `isdirempty` Checks if a directory contains no files
* :meth:`~fs.base.FS.isdirempty` Checks if a directory contains no files
* `makeopendir` Creates a directroy (if it exists) and returns an FS object for that directory
* :meth:`~fs.base.FS.makeopendir` Creates a directroy (if it exists) and returns an FS object for that directory
* `walk` Like `listdir` but descends in to sub-directories
* :meth:`~fs.base.FS.walk` Like `listdir` but descends in to sub-directories
* `walkfiles` Returns an iterable of file paths in a directory, and its sub-directories
* :meth:`~fs.base.FS.walkfiles` Returns an iterable of file paths in a directory, and its sub-directories
* `walkdirs` Returns an iterable of paths to sub-directories
* :meth:`~fs.base.FS.walkdirs` Returns an iterable of paths to sub-directories
PyFilesystem is a Python module that provides a common interface to disparate filesystems -- which allows you to write code that works with files and directories regardless of their source and location.
PyFilesystem is a Python module that provides a common interface to disparate filesystems, which allows the developer to write code that works with files and directories regardless of their source and location.
Think of PyFilesystem (FS) objects as the next logical step to Python's _file_ objects. Just as file-like objects abstract a single file, FS objects abstract the whole filesystem by providing a common interface to operations such as reading directories, getting file information, opening/copying/deleting files etc.
Think of PyFilesystem (FS) objects as the next logical step to Python's _file_ objects. Just as file-like objects abstract a single file, FS objects abstract the whole filesystem by providing a common interface to operations such as reading directories, getting file information, opening/copying/deleting files etc.
For example, if you had written a method that reads a few files from the local filesystem, it would be a trivial change if you later decided to read those files from a zip file or even over the Internet.
For example, if you had written a method that reads a few files from the local filesystem, it would be a trivial change if you later decided to read those files from a zip file or even over the Internet.