Get age of a file/dir

  • Thread starter Carl J. Van Arsdall
  • Start date
C

Carl J. Van Arsdall

I've been looking around the OS module and I haven't found anything
useful yet. Does anyone know how to get the age of a file or directory
in days? I'm using unix and don't seem to find anything that will help
me. The only function that comes close so far is

os.path.getctime(path)


However this only gets creation time on Windows, on Unix it gets the the
time of the last change. Any ideas?

Thanks!

-carl

--

Carl J. Van Arsdall
(e-mail address removed)
Build and Release
MontaVista Software
 
J

Jim

Carl said:
I've been looking around the OS module and I haven't found anything
useful yet. Does anyone know how to get the age of a file or directory
in days? I'm using unix and don't seem to find anything that will help
me. The only function that comes close so far is

os.path.getctime(path)


However this only gets creation time on Windows, on Unix it gets the the
time of the last change. Any ideas?

Thanks!

-carl

--

Carl J. Van Arsdall
(e-mail address removed)
Build and Release
MontaVista Software

Hi,
You should check out the datetime module. And convert dates to an
ordinal number.
today = datetime.date.today().toordinal()
age = today - datetime.date(year, month, day).toordinal()
Jim
 
U

url81-1

Actually this has nothing to do with datetime.datetime -- he's asking
how to find the created time of the directory.

Python has a builtin module called "stat" (afer sys/stat.h) which
includes ST_ATIME, ST_MTIME, ST_CTIME members which are times accessed,
modified, and created, respectively.

Best,
Earle Ady
 
S

Simon Forman

url81-1 said:
Actually this has nothing to do with datetime.datetime -- he's asking
how to find the created time of the directory.

Python has a builtin module called "stat" (afer sys/stat.h) which
includes ST_ATIME, ST_MTIME, ST_CTIME members which are times accessed,
modified, and created, respectively.

Best,
Earle Ady

No, the st_ctime member isn't the creation time on *nix, from the os
module docs: "st_ctime (platform dependent; time of most recent
metadata change on Unix, or the time of creation on Windows)"

I hope somebody does post a solution to this, as I'd like to know how
to get the creation time of a file on linux, et. al.

It may be impossible:
http://www.faqs.org/faqs/unix-faq/faq/part3/section-1.html

Peace,
~Simon
 
A

Antoon Pardon

I've been looking around the OS module and I haven't found anything
useful yet. Does anyone know how to get the age of a file or directory
in days? I'm using unix and don't seem to find anything that will help
me. The only function that comes close so far is

os.path.getctime(path)

However this only gets creation time on Windows, on Unix it gets the the
time of the last change. Any ideas?

On unix there is no way to get the age of a file or directory,
there is no information stored somewhere from which you can
calculate that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top