source: trunk/cic-hcap/bin/script/download-new-images.pl@ 13454

Last change on this file since 13454 was 13454, checked in by mdewsnip, 17 years ago

Renamed "grab-images.pl" to "download-all-images.pl" and added a new "download-new-images.pl" script that just downloads the files that are new or have changed.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1BEGIN {
2 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
3}
4
5
6use strict;
7use util;
8
9
10my $source_directory = "Z:\\";
11my $target_directory = "C:\\mdewsnip\\CIC\\Images\\";
12
13
14sub main
15{
16 # Find all the files in the source directory
17 if (!opendir(DIR, $source_directory)) {
18 die "Error: Couldn't read directory $source_directory\n";
19 }
20 my @directory_files = readdir(DIR);
21 closedir(DIR);
22
23 foreach my $directory_file (@directory_files) {
24 next if ($directory_file eq "." || $directory_file eq "..");
25
26 open(LOG, ">>log.txt");
27
28 my $directory_file_path = &util::filename_cat($source_directory, $directory_file);
29 print LOG "$directory_file_path ";
30 if (-f $directory_file_path) {
31 print LOG "(File)\n";
32 }
33 else {
34 print LOG "(Directory)\n";
35 my $images_revised_directory = &util::filename_cat($directory_file_path, "images REVISED");
36 if (-e $images_revised_directory) {
37 &copy_directory_to_local_drive($images_revised_directory);
38 }
39 }
40
41 close(LOG);
42 }
43}
44
45
46sub copy_directory_to_local_drive
47{
48 my ($source_directory_path) = (@_);
49
50 my $target_directory_path = $source_directory_path;
51 my $source_directory_regexp = $source_directory;
52 $source_directory_regexp =~ s/\\/\\\\/g;
53 $target_directory_path =~ s/^$source_directory_regexp/$target_directory/;
54 if (!-e $target_directory_path) {
55 print LOG " Creating new folder $target_directory_path!\n";
56 &util::mk_all_dir($target_directory_path);
57 }
58
59 # Find all the files in this directory
60 if (!opendir(DIR, $source_directory_path)) {
61 die "Error: Couldn't read directory $source_directory_path\n";
62 }
63 my @source_directory_files = readdir(DIR);
64 closedir(DIR);
65
66 foreach my $source_directory_file (@source_directory_files) {
67 next if ($source_directory_file eq "." || $source_directory_file eq ".." || $source_directory_file eq "Thumbs.db");
68
69 print LOG " $source_directory_file ";
70
71 my $source_directory_file_path = $source_directory_path . "\\" . $source_directory_file;
72 my $target_directory_file_path = $target_directory_path . "\\" . $source_directory_file;
73
74 # File doesn't exist locally, so is new
75 if (!-f $target_directory_file_path) {
76 print LOG "(New file, copying...)\n";
77 &util::cp($source_directory_file_path, $target_directory_file_path);
78 }
79 # File exists locally but file has changed
80 elsif ((-s $source_directory_file_path) != (-s $target_directory_file_path)) {
81 print LOG "(File changed, copying...)\n";
82 &util::cp($source_directory_file_path, $target_directory_file_path);
83 }
84 # File is unchanged, so ignore
85 else {
86 print LOG "(Unchanged)\n";
87 }
88 }
89}
90
91
92main(@ARGV);
Note: See TracBrowser for help on using the repository browser.