“Python Get Date Fichier Dernier modification” Réponses codées

Python Windows obtient la date modifiée du fichier

# note: test.txt can also be a file path
import os.path, time
print("Last modified: %s" % time.ctime(os.path.getmtime("test.txt")))
print("Created: %s" % time.ctime(os.path.getctime("test.txt")))
Stupid Shrew

Python Get Date Fichier Dernier modification

import os, time
# Get file's Last modification time stamp only in terms of seconds since epoch 
modTimesinceEpoc = os.path.getmtime(filePath)
# Convert seconds since epoch to readable timestamp
modificationTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(modTimesinceEpoc))
print("Last Modified Time : ", modificationTime )
Cheerful Chipmunk

Python obtenir la création de la date du fichier

import os
import platform

def creation_date(path_to_file):
    """
    Try to get the date that a file was created, falling back to when it was
    last modified if that isn't possible.
    See http://stackoverflow.com/a/39501288/1709587 for explanation.
    """
    if platform.system() == 'Windows':
        return os.path.getctime(path_to_file)
    else:
        stat = os.stat(path_to_file)
        try:
            return stat.st_birthtime
        except AttributeError:
            # We're probably on Linux. No easy way to get creation dates here,
            # so we'll settle for when its content was last modified.
            return stat.st_mtime
Cruel Cardinal

Python obtient le dernier temps de modification du fichier

import os
time = os.path.getmtime("file.txt")

print(time) # 1600113737.82
VeteranKilo

Réponses similaires à “Python Get Date Fichier Dernier modification”

Questions similaires à “Python Get Date Fichier Dernier modification”

Plus de réponses similaires à “Python Get Date Fichier Dernier modification” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code