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 12:27, 28 January 2011 by Skullerk (talk | contribs)
Jump to navigationJump to search

<source lang="python">

  1. !/usr/bin/python

import os import glob import time import shutil root = '/home/inimene/Pildid' #<-kaust kust otsib pilte ja kui on vaja subfolderitest otsida tuleb lisada /* nt: /home/inimene/Pildid/* asukoht = '/home/tardy/Pildid/' #<-asukoht kuhu loob kaustad aasta j2rgi date_file_list = [] for folder in glob.glob(root):

   for file in glob.glob(folder + '/*.jpg'):
       stats = os.stat(file)
       lastmod_date = time.localtime(stats[8])
       date_file_tuple = lastmod_date, file
       date_file_list.append(date_file_tuple)

for file in date_file_list:

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