Python reads files in the directory and generates logs

From , 3 Years ago, written in Python, viewed 241 times.
URL https://pastebin.vip/view/acef5cc0
  1. import os  
  2. from time import strftime  
  3. stamp=strftime("%Y-%m-%d %H:%M:%S")  
  4. logfile = 'F://test//m-php-framework//tmp/logs//error_report.log'  
  5. path = 'F://test//'  
  6. files = os.listdir(path)  
  7. bytes = 0  
  8. numfiles = 0  
  9. for f in files:  
  10.     if f.startswith('t'):  
  11.         info = os.stat(path + f)  
  12.         numfiles +=1  
  13.         bytes+=info[6]  
  14. if numfiles > 1:  
  15.     title = 'tiles'  
  16. else:  
  17.     title = 'file'  
  18. string = stamp + " -- " + str(numfiles) + " session" +title+","+ str(bytes)+" bytes/n"  
  19. file = open(logfile,"a")  
  20. file.writelines(string)  
  21. file.close()  
  22. #//python/1157

Reply to "Python reads files in the directory and generates logs"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website