Python directory traversal, wildcard lookup, file properties

Source: Internet
Author: User
Tags glob

# -*- coding:utf-8 -*-__author__ =  ' Magicpwn ' Import osimport timeimport  os.pathimport pprintimport globpa =  ' C:/xml/result/result.xls ' print  Os.path.dirname (PA) print  ' access time access time: ',  time.ctime (Os.path.getatime (PA)) print  ' Modified time modified: ',  time.ctime (Os.path.getmtime (PA)) print  ' Change time creation time: ',  Time.ctime (Os.path.getctime (PA)) print  ' File size: ',  os.path.getsize (PA),  ' Byte ' print  ' is the file "',  os.path.isfile (PA) print  ' absolute absolute path > ',  os.path.isabs (PA) print  ' is the dir directory? ',  os.path.isdir (PA) print  ' Is the directory ',  os.path.isdir (Os.path.dirname (PA)) print  ' exist? ',  os.path.exists (PA) print  ' link  exist ',  os.path.lexists (PA) print  ' is link ? ',  Os.path.islink (PA) # os.path.walk () iterates through all the directories of a tree species, and invokes the provided function to pass the name of the directory name as a parameter to the function #os.mkdir (' c:/hh/')     Create directory Def visit (arg, dirname, names):    print dirname, arg, names    for name in  Names:        subname = os.path.join (Dirname, name)     #连接目录和文件名         print name#  Traverse file Os.path.walk (Os.path.dirname (PA), visit,  ' user data ') #  wildcard find file For name in  glob.glob (Os.path.dirname (PA) + '/[jr0-9]* '):     print name


This article is from the "Magicpwn" blog, make sure to keep this source http://magicpwn.blog.51cto.com/10497784/1682081

Python directory traversal, wildcard lookup, file properties

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.