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
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category: Skriptimiskeeled]] | |||
<source="python"> | |||
import os, glob, time,shutil | import os, glob, time,shutil | ||
Revision as of 12:20, 28 January 2011
<source="python"> 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)