Add new comment

Umsortieren

Submitted by Erik Wegner on

Die Fotos in einem Verzeichnis werden ausgewertet und in Unterverzeichnisse verschoben.

#!/usr/bin/env python3


# Einstellungen

# Umgebung ist "linux" oder "windows"
umgebung = "linux"
#umgebung = "windows"

# Soll die Jahreszahl im Verzeichnis mit verwendet werden?
erzeuge_jahresverzeichnis = True

# Einstellungen je nach Umgebung

if umgebung == "linux":
	befehl_mkdir = "mkdir -p"
	befehl_move = "mv"
if umgebung == "window":
	befehl_mkdir = "md"
	befehl_move = "move"

# Programm

import re
import os

unproc = []
directories = []

regex1 = re.compile("^\d{4}-\d{2}-\d{2}-.*\.jpg$")


def procfilename(name):
	"Zerlege den Dateinamen in Datumsbestandteile"
	p = ""
	if name.startswith('IMG_') or name.startswith('VID_'):
		p = name[4:12]
		y = name[4:8]
		m = name[8:10]
		d = name[10:12]
		#print (name + ' => ' + y + '/' + m + '/' + d)
	if name.startswith('Lumia 1020_'):
		p = name[11:19]
		y = name[11:15]
		m = name[15:17]
		d = name[17:19]
		#print (name + ' => ' + y + '/' + m + '/' + d)
	if name.startswith('WP_2') and name.find("HDR") == -1:
		p = name[3:11]
		y = name[3:7]
		m = name[7:9]
		d = name[9:11]
		#print (name + ' => ' + y + '/' + m + '/' + d)
	if name.startswith('Office Lens'):
		p = name[12:20]
		y = name[12:16]
		m = name[16:18]
		d = name[18:20]
		#print (name + ' => ' + y + '/' + m + '/' + d)
	if regex1.match(name):
		p = name[0:10]
		y = name[0:4]
		m = name[5:7]
		d = name[8:10]
	if p == "":
		unproc.append(name)
		return
	if erzeuge_jahresverzeichnis:
		directory = os.path.join(y, m, d)
	else:
		directory = os.path.join(m, d)
	if directory not in directories:
		print (befehl_mkdir + " " + directory)
		directories.append(directory)
	print (befehl_move + ' "' + name + '" ' + directory)

def readfile(fname):
	with open(fname) as f:
		for line in f:
			procfilename(line.strip())
	print(repr(unproc))

if __name__ == "__main__":
	#readfile('filelist.txt')
	basepath = "."
	for file in os.listdir(basepath):
		if file.endswith(".jpg") or file.endswith(".mp4"):
			procfilename(file)
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.