fs.copy¶
Functions for copying resources between filesystem.
- fs.copy.copy_dir(src_fs: Union[FS, Text], src_path: Text, dst_fs: Union[FS, Text], dst_path: Text, walker: Optional[Walker] = None, on_copy: Optional[_OnCopy] = None, workers: int = 0, preserve_time: bool = False) None [source]¶
Copy a directory from one filesystem to another.
- Parameters:
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 insrc_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)
.workers (int) – Use
worker
threads to copy data, or0
(default) for a single-threaded copy.preserve_time (bool) – If
True
, try to preserve mtime of the resources (defaults toFalse
).
- fs.copy.copy_dir_if(src_fs: Union[FS, Text], src_path: Text, dst_fs: Union[FS, Text], dst_path: Text, condition: Text, walker: Optional[Walker] = None, on_copy: Optional[_OnCopy] = None, workers: int = 0, preserve_time: bool = False) None [source]¶
Copy a directory from one filesystem to another, depending on a condition.
- Parameters:
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.
condition (str) – Name of the condition to check for each file.
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 insrc_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)
.workers (int) – Use
worker
threads to copy data, or0
(default) for a single-threaded copy.preserve_time (bool) – If
True
, try to preserve mtime of the resources (defaults toFalse
).
See also
copy_file_if
for the full list of supported values for thecondition
argument.
- fs.copy.copy_dir_if_newer(src_fs: Union[FS, Text], src_path: Text, dst_fs: Union[FS, Text], dst_path: Text, walker: Optional[Walker] = None, on_copy: Optional[_OnCopy] = None, workers: int = 0, preserve_time: bool = False) None [source]¶
Copy a directory from one filesystem to another, checking times.
Deprecated since version 2.5.0: Use
copy_dir_if
withcondition="newer"
instead.
- fs.copy.copy_file(src_fs: Union[FS, Text], src_path: Text, dst_fs: Union[FS, Text], dst_path: Text, preserve_time: bool = False) None [source]¶
Copy a file from one filesystem to another.
If the destination exists, and is a file, it will be first truncated.
- fs.copy.copy_file_if(src_fs: Union[FS, Text], src_path: Text, dst_fs: Union[FS, Text], dst_path: Text, condition: Text, preserve_time: bool = False) bool [source]¶
Copy a file from one filesystem to another, depending on a condition.
Depending on the value of
condition
, certain requirements must be fulfilled for a file to be copied todst_fs
. The following values are supported:"always"
The source file is always copied.
"newer"
The last modification time of the source file must be newer than that of the destination file. If either file has no modification time, the copy is performed always.
"older"
The last modification time of the source file must be older than that of the destination file. If either file has no modification time, the copy is performed always.
"exists"
The source file is only copied if a file of the same path already exists in
dst_fs
."not_exists"
The source file is only copied if no file of the same path already exists in
dst_fs
.
- Parameters:
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.
condition (str) – Name of the condition to check for each file.
preserve_time (bool) – If
True
, try to preserve mtime of the resource (defaults toFalse
).
- Returns:
- Return type:
- fs.copy.copy_file_if_newer(src_fs: Union[FS, Text], src_path: Text, dst_fs: Union[FS, Text], dst_path: Text, preserve_time: bool = False) bool [source]¶
Copy a file from one filesystem to another, checking times.
Deprecated since version 2.5.0: Use
copy_file_if
withcondition="newer"
instead.
- fs.copy.copy_file_internal(src_fs: FS, src_path: Text, dst_fs: FS, dst_path: Text, preserve_time: bool = False, lock: bool = False) None [source]¶
Copy a file at low level, without calling
manage_fs
or locking.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) – Source filesystem.
src_path (str) – Path to a file on the source filesystem.
dst_fs (FS) – Destination filesystem.
dst_path (str) – Path to a file on the destination filesystem.
preserve_time (bool) – If
True
, try to preserve mtime of the resource (defaults toFalse
).lock (bool) – Lock both filesystems before copying.
- fs.copy.copy_fs(src_fs: Union[FS, Text], dst_fs: Union[FS, Text], walker: Optional[Walker] = None, on_copy: Optional[_OnCopy] = None, workers: int = 0, preserve_time: bool = False) None [source]¶
Copy the contents of one filesystem to another.
- Parameters:
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 insrc_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)
.workers (int) – Use
worker
threads to copy data, or0
(default) for a single-threaded copy.preserve_time (bool) – If
True
, try to preserve mtime of the resources (defaults toFalse
).
- fs.copy.copy_fs_if(src_fs: Union[FS, Text], dst_fs: Union[FS, Text], condition: Text = 'always', walker: Optional[Walker] = None, on_copy: Optional[_OnCopy] = None, workers: int = 0, preserve_time: bool = False) None [source]¶
Copy the contents of one filesystem to another, depending on a condition.
- Parameters:
dst_fs (FS or str) – Destination filesystem (URL or instance).
condition (str) – Name of the condition to check for each file.
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 insrc_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)
.workers (int) – Use
worker
threads to copy data, or0
(default) for a single-threaded copy.preserve_time (bool) – If
True
, try to preserve mtime of the resources (defaults toFalse
).
See also
copy_file_if
for the full list of supported values for thecondition
argument.
- fs.copy.copy_fs_if_newer(src_fs: Union[FS, Text], dst_fs: Union[FS, Text], walker: Optional[Walker] = None, on_copy: Optional[_OnCopy] = None, workers: int = 0, preserve_time: bool = False) None [source]¶
Copy the contents of one filesystem to another, checking times.
Deprecated since version 2.5.0: Use
copy_fs_if
withcondition="newer"
instead.
- fs.copy.copy_modified_time(src_fs: Union[FS, Text], src_path: Text, dst_fs: Union[FS, Text], dst_path: Text) None [source]¶
Copy modified time metadata from one file to another.
- fs.copy.copy_structure(src_fs: Union[FS, Text], dst_fs: Union[FS, Text], walker: Optional[Walker] = None, src_root: Text = '/', dst_root: Text = '/') None [source]¶
Copy directories (but not files) from
src_fs
todst_fs
.- Parameters:
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 insrc_fs
.src_root (str) – Path of the base directory to consider as the root of the tree structure to copy.
dst_root (str) – Path to the target root of the tree structure.