Created
January 4, 2012 22:12
-
-
Save JeffJacobson/1562458 to your computer and use it in GitHub Desktop.
Copies files and appends to the copies' filenames the date nearest the 15th or last day of the month, or nearest weekday.
This file contains hidden or 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
"""Creates copies of the timesheet files for the current pay period. | |
Place this file in the same directory as your timesheet FileMaker Pro files. | |
When you run this script, it will make copies of the files and append the | |
date of the last day of the current pay period. | |
""" | |
import sys, os, shutil, datetime, calendar | |
# Get today's date. | |
today = datetime.date.today() | |
# Set the outDate to either the 15th or 31st of the month. | |
day = today.day | |
if today.day <= 15: | |
day = 15 | |
else: | |
if today.month == 2: | |
if calendar.isleap(today.year): | |
day = 29 | |
else: | |
day = 28 | |
elif today.month in [4,6,9,11]: | |
day = 30 | |
else: | |
day = 31 | |
outDate = datetime.date(today.year, today.month, day) | |
del today, day | |
# If the outDate is a weekend, set it to the last weekday before it. | |
weekday = outDate.weekday() | |
if weekday > 4: | |
outDate = outDate - datetime.timedelta(days=weekday-4) | |
del weekday | |
# Specify the files that will be copied. | |
files = ("File1.fp7", "File2.fp7") | |
# Create copies of the specified files, appending the dates to the filenames. | |
for file in files: | |
root, ext = os.path.splitext(file) | |
try: | |
shutil.copy2(file, "%s (%s)%s" % (root, outDate, ext)) | |
except Exception, ex: | |
print ex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment