python脚本获取文件的创建于修改日期并计算时间差
由于在计算一个算法的运行时间的时候,需要将文件的创建日期与修改日期读取到,然后计算两者之差,在网上搜索了相关的程序之后,自己又修改了一下,把代码贴在这里,供以后查阅使用,也希望可以帮到其他人。
- # -*- coding: utf-8 -*-
- """
- Created on Mon Dec 12 14:59:46 2016
- @author: shenruixue
- to calculate size after filter in conv and pool
- """
- import os.path, time
- import exceptions
- class TypeError (Exception):
- pass
- if __name__ == '__main__':
- file_srx = open("train_1920_1080.set")#其中包含所有待计算的文件名
- line = file_srx.readline()
- diff_time_all = 0
- while line:
- f = line[:-1] # 除去末尾的换行符
- print (f)
- print ('***********************************************************')
- mtime = time.ctime(os.path.getmtime(f))
- ctime = time.ctime(os.path.getctime(f))
- mtime_s = (os.path.getmtime(f))
- ctime_s = (os.path.getctime(f))
- print "Last modified : %s, last created time: %s" % (mtime, ctime)
- diff_time = (int(mtime_s) - int(ctime_s))
- diff_time_all = diff_time_all + diff_time
- print "diff time is ", diff_time
- line = file_srx.readline()
- print "diff_time_all is ", diff_time_all
- file_object = open('train_1920_1080.txt', 'w')
- file_object.write(str(diff_time_all))
- file_object.close( )
python脚本获取文件的创建于修改日期并计算时间差的更多相关文章
- delphi获取文件的创建/修改时间、按时间删除指定文件下的文件
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrl ...
- 用 C# 轻松读取、改变文件的创建、修改、访问时间
创建时间是文件存入到电脑中的时间,而修改时间则是改变起内容的最后时间 // 读取文件的创建.修改.访问时间FileInfo fi = new FileInfo("C://test.txt&q ...
- C# 轻松读取、改变文件的创建、修改、访问时间 z
// 读取文件的创建.修改.访问时间FileInfo fi = new FileInfo("C://test.txt");Console.WriteLine(fi.Creation ...
- Linux如何查看文件的创建、修改时间?
Linux如何查看文件的创建.修改时间? 利用stat指令查看文件信息 三种时间的介绍 ATime --文件的最近访问时间 只要读取时间,ATime就会更新 MTime --文件的内容最近修改的时间 ...
- HIVE获取表的大小和修改日期
### 获取表的大小 hdfs dfs -du /user/hive/warehouse/database_name.db/ > 360_du ### 获取表的修改日期 hdfs dfs -ls ...
- Python 获取文件的创建时间,修改时间和访问时间
# 用到的知识# os.path.getatime(file) 输出文件访问时间# os.path.getctime(file) 输出文件的创建时间# os.path.getmtime(file) 输 ...
- python 根据现有文件树创建文件树
# -*- coding: utf-8 -*- import os, errno def fileName(path):#获取文件夹 str = '' for i in range(1,len(pat ...
- python脚本获取本机公网ip
1.获取公网IP地址方式,访问:http://txt.go.sohu.com/ip/soip 2.python脚本实现: #!/usr/bin/python # -*- coding:utf8 -*- ...
- python脚本0b文件处理
要处理的文件: 此处处理将00的数据干掉. 处理python脚本: dir_fd = open('abc.yuv','rb+') tmp_fd = open('tmp.yuv','wb+') whil ...
随机推荐
- Java知多少(36)内部类及其实例化
在 Java 中,允许在一个类(或方法.语句块)的内部定义另一个类,称为内部类(Inner Class),有时也称为嵌套类(Nested Class). 内部类和外层封装它的类之间存在逻辑上的所属关系 ...
- IDEA 最新版破解教程图解
一.打开此网站 http://idea.lanyus.com 并下载红色框框内的包 二.拷贝到idea 安装目录bin文件下 三.编辑 idea64.exe.vmoptions 和 idea.exe. ...
- Java8学习笔记(二)--三个预定义函数接口
三个函数接口概述 JDK预定义了很多函数接口以避免用户重复定义.最典型的是Function: @FunctionalInterface public interface Function<T, ...
- Writing DynamicTableEntity to Azure Storage Table
There are ample of samples available to show how to insert an object/entity to Azure Storage Table. ...
- mysql设置对外访问
报错:Host is not allowed to connect to this MySQL server解决方法 先说说这个错误,其实就是我们的MySQL不允许远程登录,所以远程登录失败了,解决方 ...
- 在MyEclipse中将Java Project转换成Web Project
在MyEclipse中将Java Project转换成Web Project 此添加方法是针对MyEclipse中添加的: 编辑工程的.project文件: 添加 <nature>com. ...
- css预处理和bootstrap
css预处理框架的比较 http://www.oschina.net/question/12_44255?sort=default&p=4 bootstrap中文网 http://v3.boo ...
- [Artoolkit] ARToolKit's SDK Structure on Android
Most applications on Android are developed in Java, and Android provides a rich framework of classes ...
- SpringBoot------Servlet3.0的注解自定义原生Servlet
1.添加需要使用的依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://w ...
- linux下通过curl访问web服务器
在通过xshell或者其他远程连接工具连接linux服务器,没安装浏览器,却要测试web服务的请求: 可以使用curl 访问web服务器 例如返回百度的主页内容 #curl www.baidu.com ...