Last active
August 29, 2015 14:24
-
-
Save asalt/08ddef08ca476d3e9d0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#check if files in directory aren't in log of previously encountered log | |
from time import sleep | |
def filechecker(): | |
print '{} : Checking for new files...'.format(time.ctime()) | |
try : log = open('filelog.log','r+U') #open log file in append mode | |
except : log = open('filelog.log','ab+') # if it doesn't exist, create it | |
files = [line.strip('\n') for line in log.readlines()] # list of all files in log | |
for f in os.listdir(inputdir): # iterate through all files in directory | |
if re.search(r'(.+\.txt$)',f ) and f not in files: #if file ends in txt and is not in the log | |
print 'New file found\n{}'.format(f+'\n') | |
try: | |
#move file | |
log.write(f+lineterm) | |
except Exception, e: print e #print any exception that may come up | |
log.close() #close log file | |
while True: | |
filechecker() | |
print 'Sleeping...' | |
sleep(3600) # sleep for an hour |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment