Commit a06b5292 authored by Davis King's avatar Davis King

Added select_oldest_file() and select_newest_file()

parent 0796ce79
......@@ -77,6 +77,40 @@ namespace dlib
return directory(f.full_name().substr(0,pos));
}
// ----------------------------------------------------------------------------------------
std::string select_oldest_file (
const std::string& filename1,
const std::string& filename2
)
{
file f1, f2;
try{f1 = file(filename1);} catch(file::file_not_found&) { return filename1; }
try{f2 = file(filename2);} catch(file::file_not_found&) { return filename2; }
if (f1.last_modified() < f2.last_modified())
return filename1;
else
return filename2;
}
// ----------------------------------------------------------------------------------------
std::string select_newest_file (
const std::string& filename1,
const std::string& filename2
)
{
file f1, f2;
try{f1 = file(filename1);} catch(file::file_not_found&) { return filename2; }
try{f2 = file(filename2);} catch(file::file_not_found&) { return filename1; }
if (f1.last_modified() > f2.last_modified())
return filename1;
else
return filename2;
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -146,6 +146,20 @@ namespace dlib
const file& f
);
// ----------------------------------------------------------------------------------------
std::string select_oldest_file (
const std::string& filename1,
const std::string& filename2
);
// ----------------------------------------------------------------------------------------
std::string select_newest_file (
const std::string& filename1,
const std::string& filename2
);
// ----------------------------------------------------------------------------------------
}
......
......@@ -165,6 +165,35 @@ namespace dlib
- returns a default initialized directory (i.e. directory())
!*/
// ----------------------------------------------------------------------------------------
std::string select_oldest_file (
const std::string& filename1,
const std::string& filename2
);
/*!
ensures
- Checks the last modification times of the two given files and returns the
filename of the oldest file, i.e., the file that has gone longest since being
modified. Ties are broken arbitrarily.
- For the purpose of comparison, a file that doesn't exist is presumed to have
a last modification time of -infinity (i.e. very far in the past).
!*/
// ----------------------------------------------------------------------------------------
std::string select_newest_file (
const std::string& filename1,
const std::string& filename2
);
/*!
ensures
- Checks the last modification times of the two given files and returns the
filename that was most recently modified. Ties are broken arbitrarily.
- For the purpose of comparison, a file that doesn't exist is presumed to have
a last modification time of -infinity (i.e. very far in the past).
!*/
// ----------------------------------------------------------------------------------------
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment