From c4a432e4670f4cf2342c00c7ffdacb0bd6f792cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 13 Jan 2025 00:52:14 +0100 Subject: [PATCH] Add convenient function to get file modified time in unix time --- Common/File/DirListing.cpp | 11 +++++++++++ Common/File/FileUtil.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/Common/File/DirListing.cpp b/Common/File/DirListing.cpp index bd027a21ce..e6140f1052 100644 --- a/Common/File/DirListing.cpp +++ b/Common/File/DirListing.cpp @@ -137,6 +137,17 @@ bool GetFileInfo(const Path &path, FileInfo * fileInfo) { return true; } +bool GetModifTimeT(const Path &filename, time_t *return_time) { + FileInfo info; + if (GetFileInfo(filename, &info)) { + *return_time = info.mtime; + return true; + } else { + *return_time = 0; + return false; + } +} + bool GetModifTime(const Path &filename, tm & return_time) { memset(&return_time, 0, sizeof(return_time)); FileInfo info; diff --git a/Common/File/FileUtil.h b/Common/File/FileUtil.h index b49c539653..858c09072d 100644 --- a/Common/File/FileUtil.h +++ b/Common/File/FileUtil.h @@ -70,6 +70,8 @@ bool IsDirectory(const Path &filename); // Returns struct with modification date of file bool GetModifTime(const Path &filename, tm &return_time); +// Same but with unix timestamp +bool GetModifTimeT(const Path &filename, time_t *return_time); // the time_t, of course, matches time_now_unix_utc(). // Returns the size of filename (64bit) uint64_t GetFileSize(const Path &filename);