Hello Dynamo users. I am pretty new in using Python and I I have been stuck with code problem. I try to create node which allows to define the Time of last modification of list of files. I can not process list of files but the node for one file works perfectly. Do you have any advices to solve it?
Are there any exceptions or errors? You are using a for loop to access each item in numberList, but you are overwriting the file variable in each iteration.
Should I use file [ x ]= time…? I doesn’t work either.
Theerror is “expected an indented block”
import os, time def getYYMMDD(filepath): statbuf = os.stat(filepath) date = time.localtime((statbuf.st_mtime)) # Debug #print str(date) # Extract out the year, month and day from the date year = date month = date day = date # YY strYear = str(year)[2:] # MM if (month <=9): strMonth = '0' + str(month) else: strMonth = str(month) # DD if (day <=9): strDay = '0' + str(day) else: strDay = str(day) return (strYear+strMonth+strDay) files = IN newlist =  for file in files: newlist.append(getYYMMDD(file)) OUT = newlist
EDIT: your input is typed in…
Thank you for reply. But it seems that files array is not defined in the code.
can show me the error code?
yes i tested on my end. it works fine?
use the new edited code. with
files = IN
Thank you it works. The only question is what if I would like to get time as well?
def getYYMMDD(filepath): epoch_datetime = os.path.getmtime(filepath) date_time = datetime.fromtimestamp(epoch_datetime) return date_time
use this function
I fix it. But wrote it in other way round. Here is the code.
But the thig is that I could not add “0” to numbers 9 and lower for hours, minutes, and seconds. Probably they are not integers for using (hour <=9)?
if (hour <=9):
strHour = ‘0’ + str(hour)
strHour = str(hour)
This does not work
Said unexpected token ‘else’
Finally I wrote workable code
Thanks for help and advices.