fs.copy

Copying files from one filesystem to another.

Functions for copying resources between filesystem.

fs.copy.copy_dir(src_fs, src_path, dst_fs, dst_path, walker=None, on_copy=None)

Copy a directory from one filesystem to another.

Parameters:
  • src_fs (FS URL or instance) – Source filesystem.
  • src_path (str) – A path to a directory on src_fs.
  • dst_fs (FS URL or instance) – Destination filesystem.
  • dst_path (str) – A path to a directory on dst_fs.
  • walker (Walker) – A walker object that will be used to scan for files in src_fs. Set this if you only want to consider a sub-set of the resources in src_fs.
  • on_copy (Function, with signature (src_fs, src_path, dst_fs, dst_path).) – A function callback called after a single file copy is executed.
fs.copy.copy_dir_if_newer(src_fs, src_path, dst_fs, dst_path, walker=None, on_copy=None)

Copy a directory from one filesystem to another. If both source and destination files exist, the copy is executed only if the source file is newer than the destination file. In case modification times of source or destination files are not available, copy is always executed.

Parameters:
  • src_fs (FS URL or instance) – Source filesystem.
  • src_path (str) – A path to a directory on src_fs.
  • dst_fs (FS URL or instance) – Destination filesystem.
  • dst_path (str) – A path to a directory on dst_fs.
  • walker (Walker) – A walker object that will be used to scan for files in src_fs. Set this if you only want to consider a sub-set of the resources in src_fs.
  • on_copy (Function, with signature (src_fs, src_path, dst_fs, dst_path).) – A function callback called after a single file copy is executed.
fs.copy.copy_file(src_fs, src_path, dst_fs, dst_path)

Copy a file from one filesystem to another. If the destination exists, and is a file, it will be first truncated.

Parameters:
  • src_fs (FS URL or instance) – Source filesystem.
  • src_path (str) – Path to a file on src_fs.
  • dst_fs (FS URL or instance) – Destination filesystem.
  • dst_path (str) – Path to a file on dst_fs.
fs.copy.copy_file_if_newer(src_fs, src_path, dst_fs, dst_path)

Copy a file from one filesystem to another. If the destination exists, and is a file, it will be first truncated. If both source and destination files exist, the copy is executed only if the source file is newer than the destination file. In case modification times of source or destination files are not available, copy is always executed.

Parameters:
  • src_fs (FS URL or instance) – Source filesystem.
  • src_path (str) – Path to a file on src_fs.
  • dst_fs (FS URL or instance) – Destination filesystem.
  • dst_path (str) – Path to a file on dst_fs.
Returns:

True if the file copy was executed, False otherwise.

fs.copy.copy_fs(src_fs, dst_fs, walker=None, on_copy=None)

Copy the contents of one filesystem to another.

Parameters:
  • src_fs – Source filesystem.
  • src_path (str) – A path to a directory on src_fs.
  • dst_fs (FS URL or instance) – Destination filesystem.
  • walker (Walker) – A walker object that will be used to scan for files in src_fs. Set this if you only want to consider a sub-set of the resources in src_fs.
  • on_copy (Function, with signature (src_fs, src_path, dst_fs, dst_path).) – A function callback called after a single file copy is executed.
fs.copy.copy_fs_if_newer(src_fs, dst_fs, walker=None, on_copy=None)

Copy the contents of one filesystem to another. If both source and destination files exist, the copy is executed only if the source file is newer than the destination file. In case modification times of source or destination files are not available, copy file is always executed.

Parameters:
  • src_fs – Source filesystem.
  • src_path (str) – A path to a directory on src_fs.
  • dst_fs (FS URL or instance) – Destination filesystem.
  • walker (Walker) – A walker object that will be used to scan for files in src_fs. Set this if you only want to consider a sub-set of the resources in src_fs.
  • on_copy (Function, with signature (src_fs, src_path, dst_fs, dst_path).) – A function callback called after a single file copy is executed.
fs.copy.copy_structure(src_fs, dst_fs, walker=None)

Copy directories (but not files) from src_fs to dst_fs.

Parameters:
  • src_fs (FS URL or instance) – Source filesystem.
  • dst_fs (FS URL or instance) – Destination filesystem.
  • walker (Walker) – A walker object that will be used to scan for files in src_fs. Set this if you only want to consider a sub-set of the resources in src_fs.