Sending by mail image files from a folder - Raspberry Pi Forums
hi, have folder ( usb stick ) containing jpg files , want, if possible folowing actions.
select file folder ( oldest )
send mail
, after succes eliminate it
take folowing 1 amd make same procedure until there no file left...
exist way inside python script?
in advance allways valuable answerds
select file folder ( oldest )
send mail
, after succes eliminate it
take folowing 1 amd make same procedure until there no file left...
exist way inside python script?
in advance allways valuable answerds
step 1. sort files in directory oldest shows first
step 2. in loop, send out each file attachment
can find information on how here: https://stackoverflow.com/questions/336 ... ttachments
step 3. remove file directory
code: select all
import os search_dir = "put full directory path here" os.chdir(search_dir) files = filter(os.path.isfile, os.listdir(search_dir)) files = [os.path.join(search_dir, f) f in files] # add path each file files.sort(key=lambda x: os.path.getmtime(x)) f in files: print(f)
can find information on how here: https://stackoverflow.com/questions/336 ... ttachments
step 3. remove file directory
code: select all
def remove(path): """ param <path> either relative or absolute. """ if os.path.isfile(path): os.remove(path) # remove file elif os.path.isdir(path): shutil.rmtree(path) # remove dir , contains else: raise valueerror("file {} not file or dir.".format(path))
raspberrypi
Comments
Post a Comment