From 5ec4e3671b18021f4ce789c944d9aeb4c283d7a2 Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Tue, 20 Jun 2023 11:11:28 +0900 Subject: [PATCH] feat(iolibs): add method to get file modified time --- src/hyfi/utils/iolibs.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hyfi/utils/iolibs.py b/src/hyfi/utils/iolibs.py index e59fdc79..0d6fae2f 100644 --- a/src/hyfi/utils/iolibs.py +++ b/src/hyfi/utils/iolibs.py @@ -1,6 +1,7 @@ """File I/O functions""" import os import re +import time from glob import glob from pathlib import Path, PosixPath, WindowsPath from typing import List, Union @@ -233,3 +234,11 @@ def copyfile(src, dst, *, follow_symlinks=True): dst = str(dst) shutil.copyfile(src, dst, follow_symlinks=follow_symlinks) logger.info(f"copied {src} to {dst}") + + @staticmethod + def get_modified_time(path): + """Return the modification time of a file""" + if not os.path.exists(path): + return None + modTimesinceEpoc = os.path.getmtime(path) + return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(modTimesinceEpoc))