Skript, mis otsib pilte ja loob kaustad aasta järgi ning tõstab vastava aasta pildi vastava aasta kausta-Python

From ICO wiki
Revision as of 13:28, 28 January 2011 by Skullerk (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

<source lang="python">

  1. Siim Kullerkupp AK21
  2. !/usr/bin/python

import os import time import shutil

asukoht = '/home/tardy/Desktop/' #<-asukoht kuhu loob kaustad aasta j2rgi

date_file_list = [] for root, dirs, files in os.walk("/home/tardy/PILT"):

  for image in files:

image = os.path.join(root, image)

       if image[-4:].lower() == ".jpg":
               try:

stats = os.stat(image)

           	    lastmod_date = time.localtime(stats[8])
           	    date_file_tuple = lastmod_date, image
           	    date_file_list.append(date_file_tuple)

os.path.join(date_file_tuple, image) except OSError: pass

for image in date_file_list:

   folder, file_name = os.path.split(image[1])
   file_date = time.strftime("%Y" , image[0])
   date = file_date.__str__()
   dir = asukoht + date
   if not os.path.isdir(dir):
       os.mkdir(dir)
   shutil.copy(folder+"/"+file_name, dir)