Christopher Martin
Half Section Map re-name script
*.py file can be downloaded here
import os, shutil
_dir = r"C:\Users\christopher.martin\Desktop"
town = raw_input("Please enter the township (28 - 30): ")"
_range = raw_input("Please enter the range (22 or 23): ")
townrange = "\T" + str(town) + "R" + str(_range)
user_directory = str(_dir) + townrange
user_output = str(user_directory) + r"\rename"
print user_directory
def get_filename(directory):
import os, time, datetime
filenames = [] # List which will store all of the full filepaths.
# Walk the tree.
for files in os.walk(directory):
for filename in files:
filenames.append(filename)
print filename
return filenames[2] # Self-explanatory.
# Run the above function and store its results in a variable.
full_file_paths = get_filename(user_directory
)#removes rename dir
if not os.path.exists(user_output):
os.makedirs(user_output)
else:
shutil.rmtree(user_output)
os.makedirs(user_output)
#function that takes index and assigns to variable
for idx, i in enumerate(full_file_paths):
print i
section = idx + 1
if idx %2 == 0:
if section < 20:
shutil.move(user_directory + "\\" + i, user_output + '\\N0' + str((section/2)) + str(town) + str(_range) + ".pdf")
else:
shutil.move(user_directory + "\\" + i, user_output + '\\N' + str((section/2)+1) + str(town) + str(_range) + ".pdf")
else:
if section < 20:
shutil.move(user_directory + "\\" + i, user_output + '\\S0' + str((section/2)) + str(town) + str(_range) + ".pdf")
else:
shutil.move(user_directory + "\\" + i, user_output + '\\S' + str((section/2)) + str(town) + str(_range) + ".pdf")
finaldir = (str(_dir) + r'\final\\' + townrange)
if os.path.exists(finaldir):
shutil.rmtree(finaldir)
shutil.copytree(user_output, finaldir)