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
Skullerk (talk | contribs)
No edit summary
Skullerk (talk | contribs)
No edit summary
 
Line 1: Line 1:
[[Category: Skriptimiskeeled]]
[[Category: Skriptimiskeeled]]
<source lang="python">
<source lang="python">
#Siim Kullerkupp AK21
#!/usr/bin/python
#!/usr/bin/python


import os
import os
import glob
import time
import time
import shutil
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   
asukoht = '/home/tardy/Desktop/'  #<-asukoht kuhu loob kaustad aasta j2rgi   
 
date_file_list = []
date_file_list = []
for folder in glob.glob(root):
for root, dirs, files in os.walk("/home/tardy/PILT"):
    for file in glob.glob(folder + '/*.jpg'):
  for image in files:
        stats = os.stat(file)
image = os.path.join(root, image)
        lastmod_date = time.localtime(stats[8])
        if image[-4:].lower() == ".jpg":
        date_file_tuple = lastmod_date, file
                try:
        date_file_list.append(date_file_tuple)
        stats = os.stat(image)
for file in date_file_list:
                lastmod_date = time.localtime(stats[8])
     folder, file_name = os.path.split(file[1])
                date_file_tuple = lastmod_date, image
     file_date = time.strftime("%Y" , file[0])
                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">

  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)