Get last modification time of a file in Dataiku managed folder

Usersyed
Usersyed Partner, Registered Posts: 29 Partner

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

Tagged:

Answers

  • FlorentD
    FlorentD Dataiker, Dataiku DSS Core Designer, Registered Posts: 25 Dataiker
    edited July 17

    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

  • Usersyed
    Usersyed Partner, Registered Posts: 29 Partner

    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'





  • FlorentD
    FlorentD Dataiker, Dataiku DSS Core Designer, Registered Posts: 25 Dataiker

    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.

  • Catalina
    Catalina Dataiker, Dataiku DSS Core Designer, Registered Posts: 135 Dataiker
    edited July 17

    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) 
    
    

Setup Info
    Tags
      Help me…