Good Afternoon.
I would like to know how to reference files or a folder to a variable in Python.
Lets say i have some files with the following names:
161225_file1.txt
161225_file2.txt
161225_file3.txt
161226_file1.txt
161226_file2.txt
161226_file3.txt
161227_file1.txt
161227_file2.txt
161227_file3.txt
i want to assign those files to a variable so i can use it in a email script i have, i also only need the files with a certain date.
Right now i only have the following:
#!/usr/bin/env python
###############################
#Imports (some library imports)
###############################
import sys
import time
import os
import re
from datetime import date,timedelta
from lib.osp import Connection
from lib.sendmail import *
###############################
#Parameters (some parameters i`ll use to send the email, like the email body message with yesterdays date)
###############################
ndays = 1
yesterday = date.today() - timedelta(days=ndays)
address = 'some.email@gmail.com'
title = '"Email Test %s"' % yesterday
attachments = ''
mail_body = "This is a random message with yesterday`s date %s" % yesterday
###############################
#Paths (Path that contain the home directory and the directory of the files i want to attach)
###############################
homedir = '/FILES/user/emails/'
filesdir = '/FILES/user/emails/TestFolder/'
###############################
#Script
###############################
#starts the mail function
start_mail()
#whatever message enters here will be in the email`s body.
write_mail(mail_body)
#gets everything you did before this step and sends it vial email.
send_mail(address,title,attachments)