fs.copy

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 or str) – Source filesystem (instance or URL).
  • src_path (str) – Path to a directory on the source filesystem.
  • dst_fs (FS or str) – Destination filesystem (instance or URL).
  • dst_path (str) – Path to a directory on the destination filesystem.
  • walker (Walker, optional) – 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 (callable, optional) – A function callback called after a single file copy is executed. Expected signature is (src_fs, src_path, dst_fs, dst_path).
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, checking times.

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 or str) – Source filesystem (instance or URL).
  • src_path (str) – Path to a directory on the source filesystem.
  • dst_fs (FS or str) – Destination filesystem (instance or URL).
  • dst_path (str) – Path to a directory on the destination filesystem.
  • walker (Walker, optional) – 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 (callable, optional) – A function callback called after a single file copy is executed. Expected signature is (src_fs, src_path, dst_fs, dst_path).
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 or str) – Source filesystem (instance or URL).
  • src_path (str) – Path to a file on the source filesystem.
  • dst_fs (FS or str) – Destination filesystem (instance or URL).
  • dst_path (str) – Path to a file on the destination filesystem.
fs.copy.copy_file_if_newer(src_fs, src_path, dst_fs, dst_path)

Copy a file from one filesystem to another, checking times.

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 or str) – Source filesystem (instance or URL).
  • src_path (str) – Path to a file on the source filesystem.
  • dst_fs (FS or str) – Destination filesystem (instance or URL).
  • dst_path (str) – Path to a file on the destination filesystem.
Returns:

True if the file copy was executed, False otherwise.

Return type:

bool

fs.copy.copy_file_internal(src_fs, src_path, dst_fs, dst_path)

Low level copy, that doesn’t call manage_fs or lock.

If the destination exists, and is a file, it will be first truncated.

This method exists to optimize copying in loops. In general you should prefer copy_file.

Parameters:
  • src_fs (FS or str) – Source filesystem.
  • src_path (str) – Path to a file on the source filesystem.
  • dst_fs (FS or str) – Destination filesystem.
  • dst_path (str) – Path to a file on the destination filesystem.
fs.copy.copy_fs(src_fs, dst_fs, walker=None, on_copy=None)

Copy the contents of one filesystem to another.

Parameters:
  • src_fs (FS or str) – Source filesystem (URL or instance).
  • dst_fs (FS or str) – Destination filesystem (URL or instance).
  • walker (Walker, optional) – 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 (callable) – A function callback called after a single file copy is executed. Expected signature is (src_fs, src_path, dst_fs, dst_path).
fs.copy.copy_fs_if_newer(src_fs, dst_fs, walker=None, on_copy=None)

Copy the contents of one filesystem to another, checking times.

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 (FS or str) – Source filesystem (URL or instance).
  • dst_fs (FS or str) – Destination filesystem (URL or instance).
  • walker (Walker, optional) – 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 (callable) – A function callback called after a single file copy is executed. Expected signature is (src_fs, src_path, dst_fs, dst_path).
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 or str) – Source filesystem (instance or URL).
  • dst_fs (FS or str) – Destination filesystem (instance or URL).
  • walker (Walker, optional) – 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.