Reputation: 143
At the moment I have incoming log files which gets updated every 10 minutes and have python code to read said data and process it in real time. The log files get imported to a folder in my C:\
drive and then from there separated into different months depending on the current month. For example, the folder at the moment where the files are read from is 'C:\user\datalog\July'
next month the logs will be coming into 'C:\user\datalog\August'
, so the path where the files are read from will change. I don't have any control over this as the log files and folders are created by an external program
Is there any way to automate the changing of directories so that during the night between July and August (and the following months) there is no loss in the reading of the log files. Any help or direction to where I could go about solving this would be greatly appreciated
Upvotes: 3
Views: 658
Reputation: 1844
You can get current month name with this code:
from datetime import datetime
import os
month = datetime.now().strftime('%B')
# Then just use month variable while constructing directory name:
logs_dir = os.path.join(r'C:\user\datalog', month)
If you're executing the script with external tools, it will be sufficient
If you're implementing the loop in Python, you'll need to get month name in each iteration.
Upvotes: 2