Seite 1 von 1

Änderungsdatum einer Datei auslesen

Verfasst: Freitag 15. September 2006, 10:00
von web
Hi

ich möchte ein Programm schreiben mit dem ich alle dateien eines ordners anzeigen lassen kann die in den letzten 7tagen geändert worden sind aber ich finde kein befehl um das änderungsdatum auszulesen könnt ihr mir helfen?

MfG
web

Re: Änderungsdatum einer Datei auslesen

Verfasst: Freitag 15. September 2006, 10:06
von gerold
web hat geschrieben:befehl um das änderungsdatum auszulesen
Hi web!

Willkommen im Python-Forum!

--> os.path.getmtime()

http://docs.python.org/lib/module-os.path.html

mfg
Gerold
:-)

Verfasst: Freitag 15. September 2006, 10:15
von web
ich habe es mit dem befehl in pythonwin versucht aber er gibt mir als fehlermeldung "is not defined" aus

was mache ich falsch? ^^

Verfasst: Freitag 15. September 2006, 10:21
von gerold
web hat geschrieben:"is not defined"
Ohne Worte!

Code: Alles auswählen

import os.path
print os.path.getmtime("<Pfad zur Datei>")

Verfasst: Freitag 15. September 2006, 10:37
von web
thx bin anfänger aber was bedeutet die zahl die ich herausbekomm?

1158308000

thx

Verfasst: Freitag 15. September 2006, 10:56
von gerold
web hat geschrieben:bin anfänger
Hi web!

Dann merke dir bitte folgendes gleich am Anfang: Lies die Dokumentation zu einem Befehl, bevor du hier eine Frage zu diesem Befehl stellst.

http://docs.python.org/lib/module-os.path.html
getmtime(path)
Return the time of last modification of path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible. New in version 1.5.2. Changed in version 2.3: If os.stat_float_times() returns True, the result is a floating point number.
http://docs.python.org/lib/module-time.html
ctime([secs])
Convert a time expressed in seconds since the epoch to a string representing local time. If secs is not provided or None, the current time as returned by time() is used. ctime(secs) is equivalent to asctime(localtime(secs)). Locale information is not used by ctime(). Changed in version 2.1: Allowed secs to be omitted. Changed in version 2.4: If secs is None, the current time is used.
gmtime([secs])
Convert a time expressed in seconds since the epoch to a struct_time in UTC in which the dst flag is always zero. If secs is not provided or None, the current time as returned by time() is used. Fractions of a second are ignored. See above for a description of the struct_time object. See calendar.timegm() for the inverse of this function. Changed in version 2.1: Allowed secs to be omitted. Changed in version 2.4: If secs is None, the current time is used.
localtime([secs])
Like gmtime() but converts to local time. If secs is not provided or None, the current time as returned by time() is used. The dst flag is set to 1 when DST applies to the given time. Changed in version 2.1: Allowed secs to be omitted. Changed in version 2.4: If secs is None, the current time is used.
mfg
Gerold
:-)

Verfasst: Freitag 15. September 2006, 10:59
von gerold

Code: Alles auswählen

>>> import os.path
>>> import time
>>> os.path.getmtime(r"C:\BcBtRmv.log")
1155809163
>>> time.ctime(os.path.getmtime(r"C:\BcBtRmv.log"))
'Thu Aug 17 12:06:03 2006'
>>> time.gmtime(os.path.getmtime(r"C:\BcBtRmv.log"))
(2006, 8, 17, 10, 6, 3, 3, 229, 0)
>>> time.localtime(os.path.getmtime(r"C:\BcBtRmv.log"))
(2006, 8, 17, 12, 6, 3, 3, 229, 1)
>>> 
mfg
Gerold
:-)