Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Is there a way to get the last modification time/upload time of a file present in a managed folder inside Dataiku?
I want this time to be displayed as part of the output of a python script.
I did try using functions like os.path.getctime, getmtime, and os.stat(path_of_file).st_mtime but all of these return the time when that script is run and not actually the modification time/the time when the file was uploaded.
I am accessing my folder in this way.
folder_path = folders
This is because using dataiku.Folder("...") does not work when the script is deployed as an API in Dataiku
I tried using folder_path.get_path_details() on this but end up getting this error
Failed to run function : class 'AttributeError' : 'str' object has no attribute 'get_path_details'
If you have access to a client (see this doc, if not), you can have access to the project (but I suppose you already do), then access to the folder.
After that the ``list_contents()`` function should do the trick.
Hi @Usersyed ,
To get the last modification time of the files present in a managed folder you can use a script like this:
import dataikuapi import datetime host="http://localhost:11200" apiKey = "***********************" project_key="PROJECTKEY" folder_id="folderID" def api_py_function(project_key, folder_id): client = dataikuapi.DSSClient(host,apiKey) folder = dataikuapi.dss.managedfolder.DSSManagedFolder(client, project_key, folder_id) contents = folder.list_contents() for i in contents["items"]: epoch_time=i["lastModified"] print(epoch_time) dtm = datetime.datetime.fromtimestamp(epoch_time / 1000) print(dtm.strftime('%Y-%m-%d %H:%M:%S.%f')) b=api_py_function(project_key,folder_id)