The pictures have randomly generated names starting with "video" such as "videotrg0494333888.jpg" so I use a regex to match the string "video" and move all files which match into a subdirectory which is formatted YEAR-MM-DD
I have cron run this script every 5 minutes.
-----
#!/usr/bin/perl
use warnings;
use File::Copy;
$datedir=`date +%F`;
chomp $datedir;
$rootdir="/var/camera";
mkdir ("$rootdir/$datedir", 0755) unless (-d "$rootdir/$datedir");
opendir(CAMERA, "$rootdir");
while (defined ($picture = readdir(CAMERA))) {
if ($picture=~/video/) {
move("$rootdir/$picture","$rootdir/$datedir");
}
}
No comments:
Post a Comment