Re: trying to check the creation date of a file



David Fickbohm wrote:
People,

I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files
exist in the folder.

Presumably you meant "intend to use the following pseudocode" (not "am using the following code") -- many of the statements (marked XXX below) are just not valid Python.


 If someone could give me an idea how to check a
creation date it would be appreciated.
Thanks
dave

def delete_old_files (t:\dm\~\users)
XXX
# find files and delete files created more than XX number of days
ago update_exist = 0
Did you mean "file_delete = 0"?

input_dir = t:\dm\~\users\xxxx.yyyyyy\zzzz
XXX
if os.path.exists (input_dir) :
files = os.listdir (input_dir)
else:
print "Unable to find input file dir: %s !!!" % input_dir
sys.exit(2)
if len(files):
Not necessary -- "for file in files" does nothing gracefully if files is empty. If it were necessary, "if not files:" is suggested as an alternative to "if len(files)".
for file in files :
file = os.path.join(input_dir) #all files in output
directory will be csv or xls, can be deleted if old enough

I think you mean "file = os.path.join(input_dir, file)"

if os.path.isfile(file): #need to check ext not file, file
name changes each day
if re.search(t:\dm\~\users\xxxxx\) and #creation date
XXX
You don't need the re module to check if the file's extension is "csv" or "xls"



gt x number of days ago t:\dm\~\users\davef.input_list.delete(file)
XXX

file_delete = 1
if file_delete:


print "\n file deleted: \n%s" %
str(t:\dm\~\users\xxxxx.input_list)
return file_delete

Now, to answer your question: You have obviously read the docs on the os module; what did you not understand about os.stat()?


I suggest you contemplate the following real-not-pseudo-code and then examine the relevant sections of the docs for os.stat(), the stat module, and the time module.

C:\junk>type st_ctime.py
import os, stat, time

def get_create_time(path):
    int_time = os.stat(path)[stat.ST_CTIME]
    str_time = time.ctime(int_time)
    return str_time

if __name__ == "__main__":
    import glob, sys
    for arg in sys.argv[1:]:
        for path in glob.glob(arg):
            create_time = get_create_time(path)
            print path, create_time
C:\junk>st_ctime.py *c*.py
checkmodules.py Fri Jun 24 22:32:57 2005
ivancodecs.py Mon Jul 11 10:03:23 2005
st_ctime.py Sat Aug 20 09:22:00 2005

C:\junk>
.



Relevant Pages

  • Re: Contact file Creation date restore
    ... contacts to since there is only one creation date for a given contact item ... folder - you would not be able to retain the original creation date. ... ContactGenie DirectPort is specifically designed for those cases where the ... this to be able to export the files to Excel format (seemed not possible ...
    (microsoft.public.outlook.contacts)
  • Re: infor on creating an empy folder view
    ... After default creation of home folderview I go in settings and select ... I tried about 20 combinations of folder view creatgion and in my case ... foder path. ... Instead if you also change the label row inside the display tab in the ...
    (Fedora)
  • Re: How to copy/deleting the file? Please help!
    ... > This code displays all the files in a folder that have a creation date ... > This code displays all the files in a folder that were created 28 or more ... >> do I compare the file to system date? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Keeping file and folder date attributes on copy/move
    ... this on an empty folder - I already know that this is true for files). ... but for a folder this will match the new creation date. ... likely winXP;-). ... winXP should behave differently to win2k in this regard (they're both ...
    (uk.comp.homebuilt)
  • Re: VBScript for automatic creation of small textfiles on Web
    ... I have actually created the file in the folder and then just tried to delete ... it with other VBScripts function as part of my trying to understand what is ... >> for VBScript text file creation and deletion within ASP. ...
    (microsoft.public.frontpage.client)