galgafou
Messages postés5Date d'inscriptionmardi 7 avril 2009StatutMembreDernière intervention14 décembre 2009
-
12 déc. 2009 à 17:52
galgafou
Messages postés5Date d'inscriptionmardi 7 avril 2009StatutMembreDernière intervention14 décembre 2009
-
14 déc. 2009 à 18:15
Bonjour à tous,
Voilà, j'aimerais faire un petit programme python dans lequel j'ai besoin de connaitre la date de création d'un fichier à partir de son chemin d'accès. Existe-il une fonction permettant d'obtenir cette info?
Merci!
cs_laurent1024
Messages postés987Date d'inscriptionmardi 31 mai 2005StatutMembreDernière intervention30 août 201225 14 déc. 2009 à 17:37
os.stat(path)¶
Perform a stat() system call on the given path. The return value is an object whose attributes correspond to the members of the stat structure, namely: st_mode (protection bits), st_ino (inode number), st_dev (device), st_nlink (number of hard links), st_uid (user id of owner), st_gid (group id of owner), st_size (size of file, in bytes), st_atime (time of most recent access), st_mtime (time of most recent content modification), st_ctime (platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows)
galgafou
Messages postés5Date d'inscriptionmardi 7 avril 2009StatutMembreDernière intervention14 décembre 2009 14 déc. 2009 à 18:15
En effet, j'ai trouvé la même fonction sur un autre site.
date_modif = os.stat(path).st-mtime renvoie le temps écoulé depuis la dernière modification du fichier.
On peut alors le modifié en date et heure (GMT) via datetime.utcfromtimestamp(date_modif)