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 |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category: Skriptimiskeeled]] | |||
<source lang="python"> | |||
#Siim Kullerkupp AK21 | |||
#!/usr/bin/python | |||
import os | |||
import time | |||
import shutil | |||
asukoht = '/home/tardy/ | asukoht = '/home/tardy/Desktop/' #<-asukoht kuhu loob kaustad aasta j2rgi | ||
date_file_list = [] | date_file_list = [] | ||
for | 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) | |||
for | lastmod_date = time.localtime(stats[8]) | ||
folder, file_name = os.path.split( | date_file_tuple = lastmod_date, image | ||
file_date = time.strftime("%Y" , | 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__() | date = file_date.__str__() | ||
dir = asukoht + date | dir = asukoht + date |
Latest revision as of 13:28, 28 January 2011
<source lang="python">
- Siim Kullerkupp AK21
- !/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)