jdupes icon indicating copy to clipboard operation
jdupes copied to clipboard

Add option to move duplicates to a different directory instead of deleting them

Open STrRedWolf opened this issue 2 years ago • 4 comments

What jdupes version are you using?

jdupes 1.20.2 (2021-11-02) 64-bit

Where did you get your copy of the jdupes binary?

[ ] Official binary from jdupes releases [x] OS distribution repository (Linux, Homebrew, etc. - put distro's name/version in text block below) [ ] I personally compiled it from source code (paste your build commands in the text block below) [ ] Other (please explain below)

Linux Mint XFCE 21.1 (Ubuntu based)

Have you searched in Issues?

[x] I have searched for my problem in Issues and I am confident that this is not a duplicate of a previous reported issue or feature request.

I have done my due diligence

[x] I am not suggesting changing the hash algorithm, storing files in a database, comparing file data blocks differently, suggesting that file sizes should be used before comparison, or other common suggestions that indicate I haven't read the documentation, code, or examined the issue tracker entries to discover that all of these things have already been implemented or won't make a difference if they were implemented. I have done my due diligence before asking for help or making a suggestion.

Issue or feature request details

I'd like to propose the following features:

 -e --log-dupes=file        Log duplicate listings to a file as well as printing them out.
                          Cannot be used with --dedupe, --delete, --link-soft, or --link-hard.
 -E --move-dupes=dir     Like --delete --no-prompt, but moves files to dir.  dir is created if it doesn't exist.
                          If --recurse is specified, the entire path is created under dir
                          and the file created under the combined path.

The first (logging to a file) would be useful for me while the second is implemented. That way I can do:

> jdupes -e ../dupes.log -f -I -r .
> perl ../jdupes-move.pl < ../dupes.log

Here's the "jdupes-move.pl" script I would use.

#!/usr/bin/perl

use strict;
use warnings;
use File::Basename;
$|=1;

if(! -e '0.Trash') {
        system "mkdir","-m4777","0.Trash";
}
if(! -d '0.Trash') {
        die "0.Trash is not a directory!";
}

while(<>) {
        chomp;
        next if(/^$/); # skip blanks.
        my $file = $_;
        my $name = basename($file);
        my $path = dirname($file);
        print "$name/$path\n";
        system "mkdir","-p","0.Trash/$path";
        system "mv",$f,"0.Trash/$path";
}

The latter feature would perform the functions of the script on duplicates to a custom directory (not just "0.Trash"). This would allow some final inspection before a rm -rf 0.Trash.

STrRedWolf avatar Feb 26 '23 13:02 STrRedWolf