A python script that gets the file name and file modification time of a certain format in the specified directory and saved as a file

Source: Internet
Author: User
Tags glob python script

Excerpt from: http://blog.csdn.net/forandever/article/details/5711319

A python script that gets the file name and file modification time of a certain format in the specified directory and saved as a file


@for &ever 2010-07-03

Function:

Gets the file name and file modification time for the specified directory under certain rules, and saves it to the specified file

The script is as follows:

#!/usr/bin/env python
#-*-Coding:utf-8-*-

‘‘‘
Created on 2010-7-2

@author: Forever
‘‘‘

Import glob, OS, datetime

#Windows
Filesread = r "C:/forever/logxyz-*.gif"
FileWrite = r "C:/forever/count.txt"

#Linux
#filesRead = r "/forever/logxyz-*.gif"
#fileWrite = r "/forever/count.txt"

if __name__ = = ' __main__ ':
List = Glob.glob (Filesread)
# Print List

Out=open (FileWrite, ' W ')
Out.write (' All GIF files: ')
Out.write ('/n ')

For I in list:
basename = Os.path.basename (i)
#print basename

Lastmod = Os.path.getmtime (i)
#print Lastmod

MyDate = datetime.datetime.fromtimestamp (int (lastmod))
#print mydate

Out.write (' filename: ' + basename + ' lastmod: ' + str (mydate))
Out.write ('/n ')

Out.close ()


A python script that gets the file name and file modification time of a certain format in the specified directory and saved as a file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.