Discover all of the brand-new features and improvements to existing capabilities in the Dataiku 11.3 updateLET'S GO

Get last modification time of a file in Dataiku managed folder

Usersyed
Level 3
Get last modification time of a file in Dataiku managed folder

Hi all,

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.

Thanks

0 Kudos
4 Replies
FlorentD
Developer Advocate

Hi,

I think, you should look at the function:

folder = dataiku.Folder("...")
folder.get_path_details()

IMO, this contains what you are looking for.

 

Hope this helps

Best

0 Kudos
Usersyed
Level 3
Author

I am accessing my folder in this way.
folder_path = folders[0]

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'





0 Kudos
FlorentD
Developer Advocate

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.

0 Kudos
CatalinaS
Dataiker

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) 

 

 

0 Kudos