os.stat I'm writing about getting time here, but I'll write a little more. Python memorandum: Refer to the text and edit the file name while copying the target file
>>> os.stat(file_path).st_mtime
>>> 1442209206.0
You can get the changed time. But this is only a value.
datetime.datetime.fromtimestamp Convert with datetime.datetime.fromtimestamp.
>>> datetime.datetime.fromtimestamp(os.stat(file_path).st_mtime)
datetime.datetime(2015, 9, 14, 14, 40, 6)
dt.strftime If you convert it to a character string with dt.strftime, it's done.
>>> dt.strftime('%Y/%m/%d %H:%M:%S')
'2015/09/14 14:40:06'
Export the date of the target file from the path to other text information.
gettime.py
# -*- coding: shift-jis -*-
def main():
pass
if __name__ == '__main__':
main()
import os
import datetime
from datetime import datetime as dt
os.chdir(r"D:\temp")
txt_file = open(r"D:\temp\photo.txt","r")
for target_line in txt_file:
if target_line == '\n':
break
target = target_line[:-1]
file_name = os.path.basename(target_line)[:-1]
print file_name
if os.path.exists(target) :
dt = datetime.datetime.fromtimestamp(os.stat(target).st_mtime)
key = dt.strftime('%Y/%m/%d %H:%M:%S')
txt_file_out = open(r"D:\python\py_date\ipad_img_file_date.csv", "a+")
txt_file_out.write(target + "," + file_name + "," + str(dt) + "," + key + "\n")
txt_file_out.close()
txt_file.close()
More on that later.
import xlrd
year_b, month_b, day_b, hour_b, minute_b, second_b = xlrd.xldate_as_tuple(udtdate_ib,book.datemode)
as_udtdate_ib = str(year_b) + '/' + str(month_b) + '/' + str(day_b)
Recommended Posts