Skript, mis otsib pilte ja loob kaustad aasta järgi ning tõstab vastava aasta pildi vastava aasta kausta-Python: Difference between revisions
From ICO wiki
Jump to navigationJump to search
Created page with 'import os, glob, time,shutil root = '/home/inimene/Pildid' #<-kaust kust otsib pilte ja kui on vaja subfolderitest otsida tuleb lisada /* nt: /home/inimene/Pildid/* asukoht = '…' |
No edit summary |
||
Line 12: | Line 12: | ||
date_file_tuple = lastmod_date, file | date_file_tuple = lastmod_date, file | ||
date_file_list.append(date_file_tuple) | date_file_list.append(date_file_tuple) | ||
for file in date_file_list: | for file in date_file_list: | ||
folder, file_name = os.path.split(file[1]) | folder, file_name = os.path.split(file[1]) |
Revision as of 19:06, 27 January 2011
import os, glob, time,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)