Skip to main content

Copies file data from one location to another.

Project description

Package py-robocopy

Copies files/data from one location to another.

Description:

py-robocopy is a Python library that serves as a wrapper for Robocopy, a robust file copying and synchronization tool available in Windows. It provides a convenient and straightforward interface to interact with Robocopy commands and perform advanced file operations within your Python applications.

Key Features:

  • Seamless Integration: py-robocopy seamlessly integrates with your Python projects, enabling you to leverage the capabilities of Robocopy directly from your codebase.

  • File Copying and Synchronization: The library simplifies file copying and synchronization tasks by utilizing Robocopy's powerful features. You can specify source and destination directories, define files to be copied, and control various copying options.

  • Advanced Copying Options: py-robocopy supports a wide range of advanced options provided by Robocopy. This includes copying subdirectories, preserving file attributes and timestamps, handling retries on failed copies, and mirroring directory structures.

  • Logging and Error Handling: The library offers built-in logging functionality, allowing you to track the progress of copying operations and save the output to log files. It also provides error-handling mechanisms to manage exceptions during the copying process.

  • Platform Compatibility: While Robocopy is primarily a Windows utility, py-robocopy is designed to work seamlessly on Windows systems where Robocopy is available.

Use Cases:

  • Automating file backup and synchronization tasks within Python applications.
  • Building data migration and replication tools that require efficient file copying.
  • Developing file management utilities with advanced copying options.
  • Integrating file synchronization functionality into custom scripts or workflows

Install the library

pip install py-robocopy

Usage

from RoboCopy import robocopy
robocopy.copy(<source-file-path>,<destination-file-path>,<options>)

Examples

Basic File Copy

from RoboCopy import robocopy
robocopy.copy("C:\\source_folder", "D:\\destination_folder")

This example demonstrates a basic file copy operation using robocopy. It copies all files and subdirectories from the source folder C:\\source_folder to the destination folder D:\\destination_folder.

File Copy with Options

from RoboCopy import robocopy

options = '/Z /R:3 /W:5'
robocopy.copy("C:\\source_folder", "D:\\destination_folder", options)

In this example, the options parameter is used to specify additional options for the copying operation. The /Z option enables restartable mode, allowing the copying process to be resumed in case of interruption. The /R:3 option sets the number of retries on failed copies to 3, and the /W:5 option sets the wait time between retries to 5 seconds.

Syntax

robocopy <source> <destination> [<file>[ ...]] [<options>]

For example, to copy a file named yearly-report.mov from c:\reports to a file share \marketing\videos while enabling multi-threading for higher performance (with the /mt parameter) and the ability to restart the transfer in case it's interrupted (with the /z parameter), type: robocopy c:\reports "\\marketing\videos" yearly-report.mov /mt /z

For more details : https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

Parameters

Parameter Description

Parameter Description
<source> Specifies the path to the source directory.
<destination> Specifies the path to the destination directory.
<file> Specifies the file or files to be copied. Wildcard characters (* or ?) are supported. If you don't specify this parameter, *.* is used as the default value.
<options> Specifies the options to use with the robocopy command, including copy, file, retry, logging, and job options.

Copy options

Option Description
/s Copies subdirectories. This option automatically excludes empty directories.
/e Copies subdirectories. This option automatically includes empty directories.
/lev:<n> Copies only the top n levels of the source directory tree.
/z Copies files in restartable mode. In restartable mode, should a file copy be interrupted, Robocopy can pick up where it left off rather than recopying the entire file.
/b Copies files in backup mode allowing Robocopy to override file and folder permission settings (ACLs). This allow copying of files you might otherwise not have access to assuming it's being run under an account with sufficient privileges.
/zb Copies files in restartable mode. If file access is denied, switches to backup mode.
/j Copies using unbuffered I/O (recommended for large files).
/efsraw Copies all encrypted files in EFS RAW mode.
/copy:<copyflags> Specifies which file properties to copy. The valid values for this option are:
  • D - Data
  • A - Attributes
  • T - Time stamps
  • X - Skip alt data streams
  • S - NTFS access control list (ACL)
  • O - Owner information
  • U - Auditing information
The default value for the /COPY option is DAT (data, attributes, and time stamps). The X flag is ignored if either /B or /ZB is used.
/dcopy:<copyflags> Specifies what to copy in directories. The valid values for this option are:
  • D - Data
  • A - Attributes
  • T - Time stamps
  • E - Extended attribute
  • X - Skip alt data streams
The default value for this option is DA (data and attributes).
/sec Copies files with security (equivalent to /copy:DATS).
/copyall Copies all file information (equivalent to /copy:DATSOU).
/nocopy Copies no file information (useful with /purge).
/secfix Fixes file security on all files, even skipped ones.
/timfix Fixes file times on all files, even skipped ones.
/purge Deletes destination files and directories that no longer exist in the source. Using this option with the /e option and a destination directory, allows the destination directory security settings to not be overwritten.
/mir Mirrors a directory tree (equivalent to /e plus /purge). Using this option with the /e option and a destination directory, overwrites the destination directory security settings.
/mov Moves files, and deletes them from the source after they're copied.
/move Moves files and directories, and deletes them from the source after they're copied.
/a+:[RASHCNET] Adds the specified attributes to copied files. The valid values for this option are:
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
/a-:[RASHCNETO] Removes the specified attributes from copied files. The valid values for this option are:
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
  • O - Offline
/create Creates a directory tree and zero-length files only.
/fat Creates destination files by using 8.3 character-length FAT file names only.
/256 Turns off support for paths longer than 256 characters.
/mon:<n> Monitors the source and runs again when more than n changes are detected.
/mot:<m> Monitors the source and runs again in m minutes if changes are detected.
/rh:hhmm-hhmm Specifies run times when new copies may be started.
/pf Checks run times on a per-file (not per-pass) basis.
/ipg:<n> Specifies the inter-packet gap to free bandwidth on slow lines.
/sj Copies junctions (soft-links) to the destination path instead of link targets.
/sl Don't follow symbolic links and instead create a copy of the link.
/mt:<n> Creates multi-threaded copies with n threads. n must be an integer between 1 and 128. The default value for n is 8. For better performance, redirect your output using /log option.

The /mt parameter can't be used with the /ipg and /efsraw parameters.

/nodcopy Copies no directory info (the default /dcopy:DA is done).
/nooffload Copies files without using the Windows Copy Offload mechanism.
/compress Requests network compression during file transfer, if applicable.
/sparse Enables retaining sparse state during copy.

File selection options

Option Description
/a Copies only files for which the Archive attribute is set.
/m Copies only files for which the Archive attribute is set, and resets the Archive attribute.
/ia:[RASHCNETO] Includes only files for which any of the specified attributes are set. The valid values for this option are:
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
  • O - Offline
/xa:[RASHCNETO] Excludes files for which any of the specified attributes are set. The valid values for this option are:
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
  • O - Offline
/xf <filename>[ ...] Excludes files that match the specified names or paths. Wildcard characters (* and ?) are supported.
/xd <directory>[ ...] Excludes directories that match the specified names and paths.
/xc Excludes existing files with the same timestamp, but different file sizes.
/xn Source directory files newer than the destination are excluded from the copy.
/xo Source directory files older than the destination are excluded from the copy.
/xx Excludes extra files and directories present in the destination but not the source. Excluding extra files won't delete files from the destination.
/xl Excludes "lonely" files and directories present in the source but not the destination. Excluding lonely files prevents any new files from being added to the destination.
/im Include modified files (differing change times).
/is Includes the same files. Same files are identical in name, size, times, and all attributes.
/it Includes "tweaked" files. Tweaked files have the same name, size, and times, but different attributes.
/max:<n> Specifies the maximum file size (to exclude files bigger than n bytes).
/min:<n> Specifies the minimum file size (to exclude files smaller than n bytes).
/maxage:<n> Specifies the maximum file age (to exclude files older than n days or date).
/minage:<n> Specifies the minimum file age (exclude files newer than n days or date).
/maxlad:<n> Specifies the maximum last access date (excludes files unused since n).
/minlad:<n> Specifies the minimum last access date (excludes files used since n) If n is less than 1900, n specifies the number of days. Otherwise, n specifies a date in the format YYYYMMDD.
/xj Excludes junction points, which are normally included by default.
/fft Assumes FAT file times (two-second precision).
/dst Compensates for one-hour DST time differences.
/xjd Excludes junction points for directories.
/xjf Excludes junction points for files.

Robocopy, short for "Robust File Copy," is a command-line utility available in Windows operating systems. It is used for copying and synchronizing files and directories, and it offers more advanced features than the regular file copy command (copy or xcopy). Robocopy was first introduced with the Windows NT 4.0 Resource Kit and has since been included as a standard command-line tool in subsequent versions of Windows.

Robocopy is a powerful tool for advanced file copying and synchronization tasks, and it can be particularly useful when dealing with large file sets or when you need to maintain file attributes, timestamps, and NTFS permissions during the copying process.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-robocopy-0.0.5.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

py_robocopy-0.0.5-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file py-robocopy-0.0.5.tar.gz.

File metadata

  • Download URL: py-robocopy-0.0.5.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for py-robocopy-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6760a6738e5eccda8e912b24331c4f7c6226803373890403e3a99738b72cdade
MD5 eea616aa1401ddf6efb274f8385e4e1e
BLAKE2b-256 cf375e750cb7ab29d3976205fc4f6ff5ace8dee21177a0ded48043e7d8e20fce

See more details on using hashes here.

File details

Details for the file py_robocopy-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: py_robocopy-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for py_robocopy-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7c8a6d6bfadcfbeaeddf1c37eac1fffc825ba3e5f4cf0b15e2e9920d8cb49a54
MD5 ce7cb5472f98e4d1542c992c9aab1b97
BLAKE2b-256 fca9d5778b2dc32ccfbfd799a50d3f0f573042deddde91a6f36f90e41fdcca47

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page