Hi Melvin and others.
Today I had time to test the script. I use the php version. I tuned it allready a bit. First I changed the first lines to find the config to this:
$config = str_replace("\\" ,"/",str_replace(getenv("USERPROFILE"),getenv("ALLUSERSPROFILE"),getenv("APPDATA")));
$config = $config."/seiz system engineering/abelcam/config.xml";
This should be universal to use on any system.
Then I added the same search for directorys in the
videosave.xml to sort also the videos.
The final version looks like this:
<?php
///////// YOU MUST CHANGE THESE LINES TO AGREE WITH YOUR SYSTEM CONFIGURATION /////////
$config = str_replace("\\" ,"/",str_replace(getenv("USERPROFILE"),getenv("ALLUSERSPROFILE"),getenv("APPDATA")));
$config = $config."/seiz system engineering/abelcam/config.xml";
date_default_timezone_set("Europe/Zurich");
// See: http://www.php.net/manual/en/timezones.php for list of php time zones.
/////////
// Dig any/all localsave paths out of AbelCam Configs
$cfg_xml = simplexml_load_file($config);
$dev_dirs = $cfg_xml->DeviceFolders->string;
foreach($dev_dirs as $dev_dir) {
if (strlen($dev_dir) > 0) {
if (substr($dev_dir, -1) != "\\") {
$dev_dir .= "\\";
}
$dev_xml=simplexml_load_file($dev_dir . "localsave.xml");
if (strlen($dev_xml->LocalSaveDir) > 0) {
if (substr($dev_xml->LocalSaveDir, -1) != "\\") {
$dev_xml->LocalSaveDir .= "\\";
}
$save_dirs[] = $dev_xml->LocalSaveDir;
}
$dev_xml=simplexml_load_file($dev_dir . "videosave.xml");
if (strlen($dev_xml->svdirectory) > 0) {
if (substr($dev_xml->svdirectory, -1) != "\\") {
$dev_xml->svdirectory .= "\\";
}
$save_dirs[] = $dev_xml->svdirectory;
}
}
}
if (count($save_dirs) == 0) {
print "No useable AbelCam configs found. Exiting.\n";
exit;
}
$yesterday = localtime(time() - 86400);
$YDyear = $yesterday[5];
$YDyday = $yesterday[7];
// Process each localsave directory
foreach ($save_dirs as $save_dir) {
print ("\n\nExamining $save_dir\n");
chdir($save_dir);
$files = glob("{*.jpg,*.JPG,*.wmv,*.WMV}", GLOB_BRACE);
$file_cnt = 0;
// Examine each .jpg file in the dir
foreach ($files as $file) {
$fmtime = localtime(filemtime($file));
$FMyear = $fmtime[5];
$FMyday = $fmtime[7];
// Is this file old enough to move?
if ($FMyear < $YDyear || $FMyday <= $YDyday) {
$FMyear += 1900;
$FMmon = $fmtime[4] + 1;
$FMmon = ($FMmon < 10) ? "0$FMmon" : "$FMmon";
$FMmday = $fmtime[3];
$FMmday = ($FMmday < 10) ? "0$FMmday" : "$FMmday";
$dest = $save_dir . "$FMyear\\$FMmon\\$FMmday";
// If destination dir does not exist, create it
if (!file_exists($dest)) {
print "Will create $dest\n";
if (mkdir($dest, 0, TRUE)) {
print "Create dir succeeded\n";
}
else {
print "Create dir FAILED!!\n";
continue;
}
}
// Finally, move the file
if(rename($file, "$dest\\$file")) {$file_cnt++;}
} //if file is old
} // foreach file
// Report what we did
if ($file_cnt == 0) {
print "Nothing to do here\n";
}
else {
print "Moved $file_cnt files\n";
}
} // foreach save_dir
?>
Works great!
Thanks a lot!
Jean-Marc