Skip to main content

Folder reference


Constructor

Constructing these yourself is not recommended. You should make an EdgeSession and access the .files property, which will return a Folder object at the root of the file system.


Methods

open

open(name, open_with=None) -> File, Folder, or object

Open an existing file or folder.

Parameters

  • name (str)
    The name of the file or folder to open. May be a delimited series of folder names like "/this/folder/file" and we will walk all folders and open the final one.
  • open_with (str)
    Optional; name of an opener to use to open the object. Examples are "pandas" or "imageio", or "file" to get a file-like object giving access to the raw bytes. If not specified, an opener will be automatically picked for you.

Returns

The opened object. By default, the exact type depends on the combination of the opener and file type. To disable this behavior and always get a plain File instance, set open_with="file".

If the object pointed to by name is a folder, open_with must not be set.

In order to open certain types of files, you may need to install additional packages.

Images

Images use the imageio (for the ImageIOOpener) or pillow_simd (for the PILOpener) package. To open an image, you must have one or both of these installed:

$ edm install imageio pillow_simd
CSV and Excel Files

Files with suffixes ".csv", ".xls", ".xlsx", ".xlsm", ".xlsb", ".odf", ".ods", ".odt" generally need Pandas and OpenPyXL installed to support the PandasOpener:

$ edm install pandas openpyxl

Raises

  • NotFound: No object of the given name exists.
  • ValueError: The given opener couldn't understand the file.

download

download(name, localpath=None)

Download to a local file. Currently, only downloading an individual file (not a folder) is supported.

Parameters

  • name (str)
    Name (or path, with "/" characters) of the remote object.
  • localpath (str) Optional; Download to this path locally. Defaults to the same basename in the current working directory.

Raises

  • NotFound: No object of the given name exists.

upload

upload(destination, fp, overwrite=False)

Upload a file to this folder.

Parameters
  • destination (str)
    The name (or path, with "/" characters) of the file to create in Edge. You can provide a path with multiple folder names separated by slashes, such as "/this/folder/path". The API will recursively create all necessary folders in the specified path.
  • fp (file-like)
    A Python file-like object which provides a read() method, returning bytes.
  • overwrite (bool)
    If True, any existing file will be overwritten. Default is False.

Raises

  • AlreadyExists: Raised if the destination already exists and overwrite is False.

make_folder

make_folder(name) -> Folder

Make a new folder.

Parameters

  • name (str)
    The name of the folder to be created within the specified directory. You can provide a path with multiple folder names separated by slashes, such as "/this/folder/path". The API will recursively create all necessary folders in the specified path.

Returns

Folder The new folder object.

Raises

  • AlreadyExists: Raised if the specified folder name already exists.

list

list() -> list(str)

List all file and folder names in this folder. The order in which they are returned is undefined.

Returns

list(str) File and folder names.


list_files

list_files() -> list(str)

List only the names of files in this folder. The order in which they are returned is undefined.

Returns

list(str) File names only.


list_folders

list_folders() -> list(str)

List only the names of folders in this folder. The order in which they are returned is undefined.

Returns

list(str) Folder names only.


exists

exists(name) -> bool

Determine if a file or folder exists.

Parameters

  • name (str)
    The name (or path, with "/" characters) of the object to test.

Returns

bool Whether the object exists.


delete

delete(object)

Delete a file or folder, given a name (or path). No error is raised if the object does not exist.

Parameters

  • object (str)
    Name (or path, with "/" components) of object to delete.

move

move(source, destination)

Move a file or folder to a new location.

Parameters

  • source (str)
    The name (or path, with "/" characters) of the file or folder to move.
  • destination (str)
    The path to which the file or folder will be moved.

Raises

  • NotFound: No object of the given source exists.
  • ValueError: destination must not be empty.
  • AlreadyExists: Raised if the destination already exists.

rename

rename(source, name)

Rename a file, while keeping it in the same folder.

Parameters

  • source (str)
    The name (not path) of the file or folder to rename.
  • name (str)
    The new name for the file or folder.

Raises

  • NotFound: No object of the given source exists.
  • ValueError: source and name must be a simple string.
  • AlreadyExists: Raised if the target file or folder name already exists.