rawfilewizard

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.clttr.info/rawfilewizard.git
Log | Files | Refs | README | LICENSE

commit 6590a3cd199359dde68fdaa917fdbd96328f32e4
parent f555d04012adfbfacff436b7de1f676ec59b7aca
Author: rwa <apollo@rw-net.de>
Date:   Sat, 28 Sep 2019 11:16:05 +0000

Merge branch '16-remove-orphaned-sidecar-files' into 'master'

Resolve "remove orphaned sidecar files"

Closes #16

See merge request guzzisti1/rawfilewizard!1
Diffstat:
Ascripts/README.md | 17+++++++++++++++++
Ascripts/orphaned_sidecar_cleaner.pl | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/scripts/README.md b/scripts/README.md @@ -0,0 +1,16 @@ +# Silkypix Helper Scripts +This rather small scripts written in [Perl](https://perl.org) provide useful function for managing the sidecar data files created by [Silkypix Developer Studio](https://silkypix.isl.co.jp/en/). + +## required perl modules +The following perl modules are required for running the scripts. +- Cwd +- File::Spec +- File::Basename +- File::Find::Rule +- File::Find +- Switch + +## description + +## orphaned sidecar cleaner +Deletes all sidecar files in the given directory or alternatively in the current working directory when the associated raw file is missing. +\ No newline at end of file diff --git a/scripts/orphaned_sidecar_cleaner.pl b/scripts/orphaned_sidecar_cleaner.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use Cwd; +use File::Spec; +use File::Basename; +use File::Find::Rule; +use File::Find; +use Switch; + +my $VERSION = 0.1; +my $PROGRAM = 'Orphaned Sidecar Cleaner'; + +# parse commandline args +# last dir will win +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 $rawfile = get_raw_filename($file); + + if ( ! -f $rawfile ) + { + print $file .'...raw file not found!'; + $delcounter++; + if ( $delete ) + { + print " Deleting"; + unlink $file or warn " failed: $!"; + } + print "\r\n"; + } + } + + print "Found $delcounter orphaned sidecar files found.\r\n"; +} + +sub get_raw_filename +{ + my ( $original_file ) = @_; + + my ( $filename, $dirs ) = fileparse($original_file); + # Silkypix Sidecar files reside in a "SILKYPIX_DS" folder, so we need to search in the parent folder + $filename =~ s/\.\d+\.sp.$//g; + return dirname($dirs) .'/'. $filename; +} + +sub show_help +{ + print $PROGRAM . ' - version ' . $VERSION . "\r\n"; + print "published under BSD 3 - Clause License \r\n"; + print "Copyright(c) 2018-2019, René Wagner\r\n"; + print "https://gitlab.com/guzzisti1/rawfilewizard \r\n"; + print "\r\n"; + print "Deletes Silkypix Sidecar files when corresponding RAW files are missing.\r\n"; + print "\r\n"; + print "commandline parameters:\r\n"; + print "orphaned_sidecar_cleaner.pl - list orphaned sidecar file in current working directory and subfolders\r\n"; + print "orphaned_sidecar_cleaner.pl -d - delete orphaned sidecar file in current working directory and subfolders\r\n"; + print "orphaned_sidecar_cleaner.pl <folder> - list orphaned sidecar file in given directory and subfolders\r\n"; + print "orphaned_sidecar_cleaner.pl -d <folder> - delete orphaned sidecar file in given directory and subfolders\r\n"; + print "orphaned_sidecar_cleaner.pl -h - show this help\r\n"; +} +\ No newline at end of file