`

python - get the modification time and creation time of a file

阅读更多

as in Unix, you know that the creation time is marked as the creation time of the inode, while the m time (so called modification time) is also the time to the inode. (creation of inode happens when you first create file/directory), while the modification bit of the inode indicate add/removing content to a directory or changing the content of a file);

 

 

To get the mtime and ctime, you can use the time module together with the os.path module, here is the cdoe that best show how you can query some time stamp associated with a file.

 

 

import os.path, time
import exceptions

class TypeError (Exception):
    pass


if __name__ == '__main__':
  if (len(os.sys.argv) < 1):
      raise TypeError()
  else:
      print "os.sys.argv[0]: %s" % os.sys.argv[0] # os.sys.argv[0] is the current file, in this case, file_ctime.py
  f = os.sys.argv[0]
  mtime = time.ctime(os.path.getmtime(f))
  ctime = time.ctime(os.path.getctime(f))
  print "Last modified : %s, last created time: %s" % (mtime, ctime)
 
分享到:
评论

相关推荐

    A Review of Time-Scale Modification of Music Signals

    时间尺度修改(Time-Scale Modification, TSM)是指在不改变音频信号音调的前提下,对其播放速度进行加快或减慢的技术。在数字音乐制作领域,TSM已成为不可或缺的工具,并广泛集成到各种音乐制作软件中。由于音乐...

    Get-Windows-File-Info.zip_creation

    标题"Get-Windows-File-Info.zip_creation"暗示了我们关注的重点是获取文件的创建时间信息。在Windows系统中,每个文件都具有创建时间、修改时间和访问时间戳,这些元数据对于追踪文件的历史记录和进行文件管理非常...

    NEJM- T-CELL-Modification

    ### NEJM-T-CELL-Modification:Chimeric Antigen Receptor-Modified T Cells in Chronic Lymphoid Leukemia #### 概述 本研究通过基因转移技术设计了一种慢病毒载体,该载体能够表达一种针对B细胞抗原CD19的嵌合...

    Instant File Searcher Professional

    Search by Name - Extension - Date and time - Size in Bytes/KB/MB/GB/TB - Creation time - Modification time - Lower or equals and Higher or equals values Very faster search using the Smart File ...

    应用Dephi 开发佳能照相机API

    * Description: This is the Sample code to show the usage of EDSDK. * * * * * ******************************************************************************* * * * Written and developed by Camera ...

    Senfore_DragDrop_v4.1

    7) If upgrading from a previous version of the Drag and Drop Component Suite, please read the document "upgrading_to_v4.txt" before you begin working on your existing projects. Note about "Property...

    Beating the Daylight Savings Time bug and getting correct file modification times

    例如,Java中的`java.time.ZonedDateTime`和`java.time.LocalDateTime`,Python的`datetime`模块,或者C++的`chrono`库,它们都可以帮助开发者处理时区转换和DST问题。 对于批处理文件(如dst_test.bat),可能是在...

    unigui0.83.5.820

    - 0000692: Runtime creation and modification of DBLookup components - 0000693: UniDBLookup bug - 0000695: UniDBGrid: Broken OnCellSelect in 0.82.0 0.82.0.803 +-------------------------------------...

    gun tar for windows

    -m, --modification-time don't extract file modified time --same-owner try extracting files with the same ownership --numeric-owner always use numbers for user/group names -p, --same-permissions ...

    Bochs - The cross platform IA-32 (x86) emulator

    - USB printer: output file creation failure now causes a disconnect - re-implemented "options" parameter for additional options of connected devices (currently only used to set the speed reported ...

    z_bus_new.zip_Z-BUS_modification_z bus

    这个"z_bus_new.zip_Z-BUS_modification_z bus"压缩包显然涉及到对Z-BUS的修改或优化,可能是为了提高性能、增加功能或者适应新的硬件需求。 "z_bus_new.m"文件很可能是一个用MATLAB编写的脚本或函数,它可能包含了...

    ftplib-4.0

    FtpModDate() - Determine modification time of file FtpSetCallback() - Establish a callback function FtpClearCallback() - Remove a callback function Server Connection FtpConnect() - Connect to a remote...

    python原文教程

    - **Book Overview**: "Python for Informatics" is a comprehensive guide designed to teach Python programming through the lens of data exploration and manipulation. This book is not just another ...

    Surface Modification of Macroporous SiO2-TiO2 Ceramic Foams via HF-etching and the Application in the Hydrogenation of Commercial Polystyrene

    SiO2-TiO2复合泡沫陶瓷的表面蚀刻及其在聚苯乙烯加氢中的应用,韩凯悦,郭文泽,聚苯乙烯(PS)催化加氢制备氢化聚苯乙烯,又称作聚环己烷基乙烯,是一种重要的聚合物改性方法,可以提高PS的热稳定性以及光学稳定性

    Universal-USB-Installer

    and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty...

    VclZip pro v3.10.1

    - If a file does not extend beyond any of the original limitations (filesizes of 4 gig or 65535 files) then no Zip64 format information is included in the archive. - property isZip64 - tells you when ...

    绿色版PocketDOS 和 绿色版TC3.0

    FILTER H - Header file for TASM2MSG.C and GREP2MSG.C GAME CPP - C example - simulated baseball game GETOPT C - Parses options in command line GREP2MSG C - Example program for Turbo C++ filters ...

    RealTimeFur.pdf

    We introduce a method for real-time rendering... Furthermore, the scheme allows real-time modification of viewing and lighting conditions, as well as local control over hair color, length, and direction.

Global site tag (gtag.js) - Google Analytics