python 2.7 - Writing a list of creation time of items in a folder -


i'm trying write text file creation date of each file in directory. had @ this question, i'm still in need of help, besides being curious why code below doesn't work.

i think i'm close. kind of works creation date of folder, want know when files created.

import os, os.path, time, datetime     mydir = '/home/user/ebay/' mydir2 = '/home/user/' def writefiles():     open(mydir2 + '/items.txt', "wb") a:         path, subdirs, files in os.walk(mydir):             file in files:                 a.write(file+' , '+(time.ctime(os.path.getctime(file))) + os.linesep) writefiles() 

i error message:

oserror: [errno 2] no such file or directory: 'pkv20zrzms' 

this odd, because there file called 'pkv20zrzms'. tried add directory location didn't make difference.

the reason think i'm close when change (os.path.getctime(file) (os.path.getctime(path) creation date of folder, this:

pkv20zrzms , fri mar 20 13:43:31 2015 qzzo0zuatm , fri mar 20 13:43:31 2015 tm5f8lhgcd , fri mar 20 13:43:31 2015 vgmcbgdju0 , fri mar 20 13:43:31 2015 ja7bwa5uei , fri mar 20 13:43:31 2015 

the following works me, perhaps there's path? note have trailing slash in mydir2 might mess path you're writing when concatenate '/items.txt'.

import os, os.path, time, datetime      mydir = '/home/xnx/temp' mydir2 = '/tmp'  def writefiles():     open(mydir2 + '/items.txt', "wb") a:         path, subdirs, files in os.walk(mydir):             file in files:                 a.write(file+' , '+(time.ctime(os.path.getctime(                            os.path.join(path, file)))) + os.linesep) writefiles() 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -