ich bin neu in python und ich brauch ein programm mit dem ich alle dateien des selben tages automatisch in einen ordner transferiere und diese dann zippe.
also um das besser zu verdeutlichen, in einem ordner sind dateien mit den namen :
20120510_tag_eins_pic.jpg
20120510_tag_eins_sheet.jpg
20120510_tag_eins_sheet2.jpg
20120511_tag_zwei_pic.jpg
20120511_tag_zwei_sheet.jpg
20120511_tag_zwei_sheet2.jpg
usw.
nun muessen alle dateien des selben tages in einen ordner und das fuer jeden tag eines monats und dann muss der komplette monat gezipt werden.
folgendes habe ich schon, jedoch bekommt jede datei damit einen anderen ordner und ich weiss nich wie ich das am besten so umschreibe das alle eines tages in einem sind.
Code: Alles auswählen
import os, re, shutil
tfolder = 'D:/Testing/src/'
os.chdir(tfolder)
re_year19xxxxxx = re.compile('(19[0-9][0-9][0-9][0-9])')
re_year20xxxxxx = re.compile('(20[0-9][0-9][0-9][0-9])')
re_ed = re.compile('(ED[0-9])')
destPath = 'D:/Testing/Dest/'
def analyse_file_name(fname):
filePath, coords = os.path.split(fname) #the new folders will be named according to the first 4 characters of the original file name
coordsFolder = coords[:53]
coordsFname = coords[:53]
coordsExt = os.path.splitext(fname)
year = 'year' #create variable year
ed = 'ed' #create variable ed to store the edition number if necessary
bname = fname #the original file name
for re_year in (re_year19xxxxxx, re_year20xxxxxx):
rx = re_year.search(fname) #search for regex in the file name and store it in rx
if rx:
year = rx.group(1) #if the regex is found, store the year
bname.replace(year, ' ')
res = re_ed.search(fname)
if res:
ed = res.group(1)
bname.replace(ed, ' ')
os.chdir(destPath)
if year is 'year':
fname2 = os.path.join(destPath, coordsFolder) + '\\' + coordsFname + coordsExt[1]
else:
fname2 = os.path.join(destPath, coordsFolder,year,ed) + '\\' + coordsFname + coordsExt[1]
print('%s -> %s' % (fname, fname2)) #debug print
dirn, _ = os.path.split(fname2)
if not os.path.exists(dirn):
os.makedirs(dirn)
shutil.copy(fname, fname2)
for root, dirs, files in os.walk(tfolder):
for name in files:
fn = os.path.join(root, name)
analyse_file_name(fn)
kann mir da jemand helfen ?
grüße zeromancer