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