I am trying to create what should be a very simple script, though I'm having a very difficult time getting it to work. All I want to do is create a new copy of a master file once per week and do my work on the copy. I plan to set this up in task manager to automatically run the script weekly (on Sunday nights for example).
The script will:
- Search for the previous editing file
- Delete the previous editing file
- Copy the master file and create a new editing file
- When creating the new editing file, it will also grab the date of creation and add that to the name of the editing file
Everything works except the part where it searches the old file. Since the file name is going to change weekly (given a new date in the filename each time), it will have to use a wildcard search to make sure it finds the old edit file. For instance, to get rid of these two: "new03-04-06.mxd" & "new03-11-06.mxd", I would need it to look for "new*.mxd"
I tried using the "glob" function but it then tells me that I can't delete a "list". I'm now out of ideas. Hopefully someone on here can help out. I will post the code for the script below:
import os, sys, shutil, time
# Define variables
date = time.strftime("%m-%d-%y")
oldmxd = ('new*.mxd')
mastermxd = ("master.mxd")
newmxd = ("new" + date + ".mxd")# Delete the old .mxd
os.remove(oldmxd)# Create the new .mxd
shutil.copy(mastermxd, newmxd)
print "New .mxd created: " + newmxd
All help is most appreciated!
P.S. the reason for this script is that our GIS map files (.mxd) tend to lose performance over a period of time, and must be deleted and created fresh again once per week.