Show the filename and modified date in labels


I need to show the filename of a document inside a folder on the network, may be using labels or another component can use, and in addition to show the modified date in another label.

I’ll admit, I’m having trouble visualizing what you want to do. Are you looking to list all files in a folder, or do you already have the document and you just need to get the information for it?

I´m looking to list all files in a folder (*.txt). the reason to show them incluiding the modified date is to make sure we have storaged the most recent document.


I’d be inclined to use a table for this:

import os, time

pathName = 'c:\\Test'

# get the list of filenames
fileList = os.listdir(pathName)

headers = ['filename', 'date']
dataOut = []

for fileName in fileList:
  # getmtime returns a Unix timestamp, so we use ctime to make it more usable format.
  fileDate = time.ctime(os.path.getmtime(pathName + '/' + fileName))
  dataOut.append([fileName, fileDate])
filedata = system.dataset.toDataSet(headers, dataOut)

# send sorted dataset to a table-- sorted by date descending
event.source.parent.getComponent('Table').data = system.dataset.sort(filedata, 'date', 0)
1 Like