バッチソリューション:
FOR / Rを使用して、すべてのサブフォルダーを一覧表示できます。
FOR /R "V:\Photo Library" %G in (.) do @echo %G
少し変更して、すべてのフォルダに対してコマンドを起動します。
FOR /R "V:\Photo Library" %G in (.) do for /F "delims=" %i in (listimagescopy.txt) do xcopy "%G\%i.jpg" "V:\Current Library\Work Zone" /D /Y
xcopy / Dは新しいファイルのみをコピーし、/Yは確認なしで上書きします。バッチファイルで、ソースが存在するかどうかを確認するには、次のように使用できます。
@echo off
FOR /R "V:\Photo Library" %%G in (.) do (
for /F "delims=" %%i in (listimagescopy.txt) do (
if exist "%%G\%%i.jpg" xcopy "%%G\%%i.jpg" "V:\Current Library\Work Zone" /D /Y
)
)
Perlソリューション:
use strict;
use warnings;
use File::Find;
use File::Copy;
#filenames to match
my $filenames = join '|', map "\Q$_\E", split "\n", <<END;
filename1
otherfilename
another_one
etc
END
my $src_path = "V:\\Photo Library";
my $dst_path = "V:\\Current Library\\Work Zone";
find({ wanted => \&process_file, no_chdir => 1 }, $src_path);
sub process_file {
if (-f $_) {
# it's a file
if (/\/($filenames).jpg$/) {
# it matches one of the rows
if ((stat($_))[9] > ((stat("$dst_path/$1.jpg"))[9] // 0)) {
# it's newer than the file in the destination
# or destination file does't exist
print "copying $_ ...\n";
copy($_, $dst_path) or die "File $_ cannot be copied.";
}
}
}
}