Browse code

implements #0000018 default to list only mode and add -m commandline switch

René Wagner authored on 30.09.2019 20:00:28
Showing 2 changed files

... ...
@@ -10,7 +10,7 @@ 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
+- File::Copy
14 14
 - Switch
15 15
 
16 16
 ## description
... ...
@@ -13,38 +13,41 @@ use File::Find::Rule;
13 13
 use File::Copy;
14 14
 use Switch;
15 15
 
16
-my $VERSION = '0.2';
16
+my $VERSION = '0.3';
17 17
 my $PROGRAM = 'JpegDivider';
18 18
 
19 19
 my $SUBFOLDER = 'JPEG';
20 20
 # parse commandline args
21 21
 # last dir will win
22 22
 my $work_dir = getcwd;
23
+my $move_flag = 0;
23 24
 
24 25
 foreach my $arg ( @ARGV ) 
25 26
 {
26 27
 	switch ( $arg )
27 28
 	{
28 29
 		case '-h'  	{ show_help(); exit; }
30
+		case '-m'   { $move_flag = 1; }
29 31
 	 	else		{ if ( -d $arg ) { $work_dir = $arg } }
30 32
 	}
31 33
 }
32 34
 
33
-main($work_dir);
35
+main($work_dir, $move_flag);
34 36
 
35 37
 exit 0;
36 38
 
37 39
 sub main
38 40
 {
39
-	my ( $dir ) = @_;
40
-	my ( $move_counter ) = 0;
41
+	my ( $dir, $move_flag ) = @_;
42
+	my $move_counter = 0;
41 43
 
42 44
 	say "working directory: $dir";
43
-	say "moving jpeg files to subfolder: $SUBFOLDER \r\n";
45
+	say 'action           : '. ($move_flag ? 'move' : 'list only');
46
+	say "subfolder        : $SUBFOLDER";
47
+	say '';
44 48
 	
45 49
 	my $destination_dir = "$dir\/$SUBFOLDER";
46
-
47
-	if ( ! -d $destination_dir )
50
+	if ( $move_flag && ! -d $destination_dir )
48 51
 	{
49 52
 		mkdir $destination_dir or die "Could not create destination dir $_ : $!";
50 53
 	}
... ...
@@ -55,17 +58,20 @@ sub main
55 58
 	{
56 59
 		print $file .'...';
57 60
 		$move_counter++;
58
-		if ( move($file, $destination_dir. '/' .basename($file) ) )
59
-		{ 
60
-			say "moved.";
61
-		}
62
-		else
61
+		if ( $move_flag )
63 62
 		{
64
-			say "move failed: $!";
63
+			if ( move($file, $destination_dir. '/' .basename($file) ) )
64
+			{ 
65
+				say "moved.";
66
+			}
67
+			else
68
+			{
69
+				say "move failed: $!";
70
+			}
65 71
 		}
66 72
 	}
67 73
 	
68
-	say "\r\nmoved $move_counter jpeg files to subfolder.";
74
+	say "\r\nfound $move_counter jpeg files to subfolder.";
69 75
 }
70 76
 
71 77
 sub show_help
... ...
@@ -78,7 +84,9 @@ sub show_help
78 84
 	say 'Moves JPEG files to a designated subfolder, by default "JPEG"';
79 85
 	say '';
80 86
 	say 'commandline parameters:';
81
-	say 'jpegdivider.pl - create a subfolder "JPEG" in the current working dir and move jpeg files in there';
82
-	say 'jpegdivider.pl <folder> - create a subfolder "JPEG" in the given directory and move jpeg files in there';
87
+	say 'jpegdivider.pl - list all jpeg files in the current working dir';
88
+	say 'jpegdivider.pl -m - create a subfolder "JPEG" in the current working dir and move jpeg files in there';
89
+	say 'jpegdivider.pl <folder> - list all jpeg files in the given directory';
90
+	say 'jpegdivider.pl -m <folder> - create a subfolder "JPEG" in the given directory and move jpeg files in there';
83 91
 	say 'jpegdivider.pl -h - show this help';
84 92
 }