Browse code

Merge branch 'jpegdivider'

René Wagner authored on 30.09.2019 18:20:29
Showing 2 changed files

... ...
@@ -10,10 +10,14 @@ The following perl modules are required for running the scripts.
10 10
 - File::Basename
11 11
 - File::Find::Rule
12 12
 - File::Find
13
+- File::Copy;
13 14
 - Switch
14 15
 
15 16
 ## description
16 17
 
18
+### jpeg divider
19
+Moves all jpeg files (suffixes .jpg and .jpeg) in a folder to the subfolder JPEG.
20
+
17 21
 ### orphaned sidecar cleaner
18 22
 Deletes all sidecar files in the given directory or alternatively in the current working directory when the associated raw file is missing.
19 23
 
20 24
new file mode 100644
... ...
@@ -0,0 +1,77 @@
1
+#!/usr/bin/perl
2
+# Copyright(c) René Wagner 2019
3
+# published under BSD 3-Clause License
4
+# https://www.codewolke.net/silkypix-helper/
5
+
6
+use warnings;
7
+use strict;
8
+use Cwd;
9
+use File::Basename;
10
+use File::Find;
11
+use File::Find::Rule;
12
+use File::Copy;
13
+use Switch;
14
+
15
+my $VERSION = '0.2';
16
+my $PROGRAM = 'JpegDivider';
17
+
18
+my $SUBFOLDER = 'JPEG';
19
+# parse commandline args
20
+# last dir will win
21
+my $work_dir = getcwd;
22
+
23
+foreach my $arg ( @ARGV ) 
24
+{
25
+	switch ( $arg )
26
+	{
27
+		case '-h'  	{ show_help(); exit; }
28
+	 	else		{ if ( -d $arg ) { $work_dir = $arg } }
29
+	}
30
+}
31
+
32
+main($work_dir);
33
+
34
+exit 0;
35
+
36
+sub main
37
+{
38
+	my ( $dir ) = @_;
39
+	my ( $move_counter ) = 0;
40
+
41
+	print "working directory: $dir \r\n";
42
+	print "moving jpeg files to subfolder:\r\n";
43
+	
44
+	my $destination_dir = "$dir\/$SUBFOLDER";
45
+
46
+	if ( ! -d $destination_dir )
47
+	{
48
+		mkdir $destination_dir or die "Could not create destination dir $_ : $!";
49
+	}
50
+	
51
+	my @files = File::Find::Rule->file()->name( '*.jpg', '*.jpeg', '*.JPG', '*.JPEG' )->maxdepth(1)->in( $dir );
52
+	
53
+	foreach my $file ( @files )
54
+	{
55
+		print $file .'...';
56
+		$move_counter++;
57
+		move($file, "$destination_dir\/".basename($file) ) or warn " move failed: $!";
58
+		print "\r\n";
59
+	}
60
+	
61
+	print "\r\nmoved $move_counter jpeg files to subfolder.\r\n";
62
+}
63
+
64
+sub show_help
65
+{
66
+	print $PROGRAM . ' - version ' . $VERSION . "\r\n";
67
+	print "published under BSD 3 - Clause License \r\n";
68
+	print "Copyright(c) 2019 René Wagner\r\n";
69
+	print "https://www.codewolke.net/silkypix-helper/ \r\n";
70
+	print "\r\n";
71
+	print "Moves JPEG files to a designated subfolder, by default 'JPEG'\r\n";
72
+	print "\r\n";
73
+	print "commandline parameters:\r\n";
74
+	print "jpegdivider.pl - create a subfolder 'JPEG' in the current working dir and move jpeg files in there\r\n";
75
+	print "jpegdivider.pl <folder> - create a subfolder 'JPEG' in the given directory and move jpeg files in there\r\n";
76
+	print "jpegdivider.pl -h - show this help\r\n";
77
+}