Add option to preserve last modified and created timestamps in Transfer Files node

Currently when using the Transfer Files node the last modified and created file attributes are both changed to the current time.
In many cases I’d like this to be preserved but there’s no option do do this. I suggest a checkbox to ‘Preserve timestamps on files’

@bobpeers there was this workaround involving R:

@mlauber71 Thanks. I ended up moving the files using python but the low-code approach would have been easier :slight_smile:

1 Like

Maybe you can share an example how to do this with the bundled Python

Pseudo-code is something like this to reset the last modified and created timestamps.

import os
import shutil
import datetime

src_dir = "source directory"
dst_dir = "destination directory"

# set threshhold for modified time
date_threshold = datetime.datetime(2022, 12, 31, 23,59,59)  # Example date threshold of December 31, 2022

#walk directory
for filename in os.listdir(src_dir):
    filepath = os.path.join(src_dir, p)
    if os.path.isfile(filepath):
        file_modified_time = datetime.datetime.fromtimestamp(os.path.getmtime(filepath))
        # if file is older than threshhold
        if file_modified_time < date_threshold:
            # get original timestamps
            atime = os.path.getatime(filepath)
            mtime = os.path.getmtime(filepath)
            shutil.move(filepath, os.path.join(dst_dir, p))
           # apply timestamps to moved file
            os.utime(os.path.join(dst_dir, p), (atime, mtime))

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.