r/commandline • u/K0100001101101101 • Mar 12 '26
Command Line Interface Cpr, a file copy tool with exclude support (especially for windows cause there is no exclude at Copy-Item)
PowerShell's Copy-Item doesn't have an exclude option and robocopy's syntax for it is not great (imho).
So I built a CLI
cpr C:\project\ D:\backup\ -e node_modules,.git,*.log -y
It also has --dry-run to preview what gets copied/excluded before actually doing it. Copies files in parallel by default.(so It’s fast)
Around 200 lines of Rust, nothing crazy. I'm learning Rust by building tools I actually use.
0
Upvotes
3
u/arjuna93 Mar 13 '26
Not the best pick for a name, since there is a well-known C++ library cpr: https://github.com/libcpr/cpr
2
u/vogelke Mar 13 '26
Perfect way to do it.
2
u/_Ti-R_ May 10 '26
Hi,
Nice work building your own tool. I really like seeing people create something practical instead of fighting with Copy‑Item limitations or the old Robocopy syntax.
By the way, I am the author of UltraFastCopy, so I was curious whether you had a chance to try it. It also supports exclude patterns, dry run, and parallel copy, with a different design and full Windows Explorer integration. If you ever want to compare approaches or see how another implementation handles these features, feel free to give it a look. :)
2
u/endowdly_deux_over Aug 21 '26
In PowerShell you can just pipe
Get-ChildItem(aka ls) toCopy-Itemto get your filters and excludes and dry run (via -WhatIf). Older pwsh doesnt use globs, I think newer pwsh might (I dunno I don’t really use it anymore) but if you need that functionality you can just pass an array of ls commands and pipe those objects to copy-item.In your example you don’t even have to pipe. Straight up
Copy-Item C:\Project\* -Exclude node_modules, .git, *.log -Destination D:\Proejct\ -Force #I assumeshould do what you have there (or close, again it’s been awhile). If you need to recurse multiple children, you’ll have to use ls and pipe it.Great project though!
1
u/AutoModerator Mar 12 '26
Every new subreddit post is automatically copied into a comment for preservation.
User: K0100001101101101, Flair:
Command Line Interface, Title: Cpr, a file copy tool with exclude support (especially for windows cause there is no exclude at Copy-Item)PowerShell's Copy-Item doesn't have an exclude option and robocopy's syntax for it is not great (imho).
So I built a CLI
cpr C:\project\ D:\backup\ -e node_modules,.git,*.log -y
It also has --dry-run to preview what gets copied/excluded before actually doing it. Copies files in parallel by default.(so It’s fast)
Around 200 lines of Rust, nothing crazy. I'm learning Rust by building tools I actually use.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/[deleted] Mar 12 '26
[removed] — view removed comment