Python filters information for a specific file in the format output to txt

Source: Internet
Author: User

Recently engaged in the database, in order to put the picture file information into the database table, I began to study Python list image files, which found that because the IE temporary files have a lot of unwanted pictures, you need to filter out some files.

Finally, the path, file name, and time of all required picture files are output in Python to a txt

1 ImportOS2 Import Time3 4 defisobjfile (path, filename, suffix, shield):5     #determines whether a file ends in a string in suffix and does not have an unwanted file path6Flag1 =False7      forTmpinchsuffix:8         ifFilename.endswith (TMP):9Flag1 =TrueTenFlag2 =True One      forTmpinchShield: A         ifTmpinchPath: -Flag2 =False -     returnFlag1 andFlag2 the  - defGetpicinfo (objpath, objfile, suffix, shield): -     #find file output to txt -f = open (objfile,'W') +g =Os.walk (Objpath) -      forPath,d,filelistinchg: +          forFileNameinchfilelist: ATmpname =Filename.lower () at             ifisobjfile (path, tmpname, suffix, shield): -F.write (path +',' ) -F.write (filename +',' ) -TimeStamp =Os.stat (os.path.join (path, filename)). St_ctime -Timearray =time.localtime (TimeStamp) -Styletime = Time.strftime ("%m%d%Y", Timearray) inF.write (Styletime +',#\n') - f.close (); to  +Path ='G:' -File ='Picname.txt' thesuffix = ['jpg','PNG','gif' ] *Shield = ['Temporary Files','Office','SDL' ] $Getpicinfo (Path, File, suffix, shield)

Python filters information for a specific file in the format output to txt

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.