commit 22efbb727194eb9068a17bb1255f11b1a0c4c2d3
parent 9e5250d5d23abd299ddeb55add573807dd1a3baf
Author: guzzisti <apollo@rw-net.dew>
Date: Sat, 28 Sep 2019 13:06:58 +0200
add multiversion sidecar cleaner.pl
Diffstat:
1 file changed, 94 insertions(+), 0 deletions(-)
diff --git a/multiversion_sidecar_cleaner.pl b/multiversion_sidecar_cleaner.pl
@@ -0,0 +1,94 @@
+#!/usr/bin/perl
+# Copyright(c) René Wagner 2019
+# published under BSD 3-Clause License
+# https://code.rw-net.de/silkypix_helper/
+
+use warnings;
+use strict;
+use Cwd;
+use File::Basename;
+use File::Find::Rule;
+use File::Find;
+use Switch;
+
+my $VERSION = 0.1;
+my $PROGRAM = 'Multiversion Sidecar Cleaner';
+
+my $delete_flag = 0;
+my $delete_dir = getcwd;
+
+foreach my $arg ( @ARGV )
+{
+ switch ( $arg )
+ {
+ case '-h' { show_help(); exit; }
+ case '-d' { $delete_flag = 1; }
+ else { if ( -d $arg ) { $delete_dir = $arg } }
+ }
+}
+
+print "working directory: $delete_dir \r\n";
+
+main($delete_dir, $delete_flag);
+
+exit 0;
+
+sub main
+{
+ my ( $dir, $delete ) = @_;
+ my ( $delcounter ) = 0;
+
+ # alle Dateien in allen Unterordnern *.spd *.spf suchen
+ my $rule = File::Find::Rule->new;
+ $rule->file;
+ $rule->name( '*.spd', '*.spf' );
+ my @files = $rule->in( $dir );
+
+ my $file;
+ foreach $file ( @files )
+ {
+ my $nextfile = get_next_filename($file);
+
+ if ( -f $nextfile )
+ {
+ print $file .'...newer file found!';
+ $delcounter++;
+ if ( $delete )
+ {
+ unlink $file ? print ' File deleted' : print ' Deletion failed';
+ }
+ print "\r\n";
+ }
+ }
+
+ print 'Found '. $delcounter .' duplicate file versions.';
+}
+
+sub get_next_filename
+{
+ my ( $original_file ) = @_;
+
+ if ( -f $original_file )
+ {
+ my ( $filename, $dirs, $suffix ) = fileparse($original_file, qr/\.sp\w/);
+ my ( $file, $version ) = split /\.([^\.]+)$/, $filename;
+ return $dirs . $file .'.'. ($version + 1) . $suffix;
+ }
+}
+
+sub show_help
+{
+ print $PROGRAM . ' - version ' . $VERSION . "\r\n";
+ print "published under BSD 3 - Clause License \r\n";
+ print "Copyright(c) 2019 René Wagner\r\n";
+ print "https://code.rw-net.de/silkypix_helper/ \r\n";
+ print "\r\n";
+ print "Deletes Silkypix Sidecar files when newer versions of the files are available.\r\n";
+ print "This usually happens when a file is opened in a newer version of Silkypix, as the sidecar files are version specific.\r\n";
+ print "\r\n";
+ print "commandline parameters:\r\n";
+ print "duplicate_sidecar_cleaner.pl - list duplicate sidecar file versions in current working directory and subfolders\r\n";
+ print "duplicate_sidecar_cleaner.pl -d - delete duplicate sidecar file versions in given directory and subfolders\r\n";
+ print "duplicate_sidecar_cleaner.pl <folder> - list duplicate sidecar file versions in given directory and subfolders\r\n";
+ print "duplicate_sidecar_cleaner.pl -d <folder> - delete duplicate sidecar file versions in given directory and subfolders\r\n";
+ print "duplicate_sidecar_cleaner.pl -h - show this help\r\n";}