1 Star 0 Fork 3

赵首智/管理员仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
file1.py 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
# Script Name : fileinfo.py
# Author : Not sure where I got this from
# Created : 28th November 2011
# Last Modified :
# Version : 1.0
# Modifications :
# Description : Show file information for a given file
# get file information using os.stat()
# tested with Python24 vegsaeat 25sep2006
from __future__ import print_function
import os
import stat # index constants for os.stat()
import sys
import time
if sys.version_info >= (3, 0):
raw_input = input
file_name = raw_input("Enter a file name: ") # pick a file you have
count = 0
t_char = 0
try:
with open(file_name) as f:
line = f.readline()
t_char += len(line)
while line:
count += 1
line = f.readline()
t_char += len(line)
except FileNotFoundError as e:
print(e)
sys.exit()
file_stats = os.stat(file_name)
# create a dictionary to hold file info
file_info = {
'fname': file_name,
'fsize': file_stats[stat.ST_SIZE],
'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p",
time.localtime(file_stats[stat.ST_MTIME])),
'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p",
time.localtime(file_stats[stat.ST_ATIME])),
'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p",
time.localtime(file_stats[stat.ST_CTIME])),
'no_of_lines': count,
't_char': t_char
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhao-shouzhi/administrators-warehouse.git
git@gitee.com:zhao-shouzhi/administrators-warehouse.git
zhao-shouzhi
administrators-warehouse
管理员仓库
master

搜索帮助