Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import date
- import glob
- import os
- ## Set version number.
- version = '1.0'
- ## Get the current date.
- now = date.today()
- ## Format it.
- today = now.strftime("%m-%d-%y")
- ## Set request type. May be improved by making it interactive later.
- request = 'Parts'
- ## Get to the parts request directory.
- os.chdir('S:\\Parts Requisitions\\Electrical Requests\\2013')
- ## Make a list of the filenames that start with a number and end with
- ## ".pdf".
- filelist = glob.glob('[0-99999]*.pdf')
- ## Sort the list so that the newest request filename is the first index.
- filelist.sort(reverse=True)
- ## Pull out the last requests filename.
- lastreq = filelist[0]
- ## Parse out the different parts of the file name.
- templist = lastreq.split()
- ## Pull out the portion of the file name that contains the number.
- lastnum = templist[0]
- ## Change the string into a integer.
- lastnum = int(lastnum)
- ## Increment the number by 1.
- newnum = lastnum + 1
- ## Concatenate the parts of the new request file name into a single
- ## string
- filename = str(newnum) + ' ' + request + ' ' + today + ".pdf"
- ## Open a writable file with the proper file name.
- placeholderfile = open(filename, 'w')
- ## Place a summary of how the file was created in the file as plain
- ## text for anyone who wants to know more.
- placeholderfile.write('This is a placeholder file for the next parts\n'
- 'request number in line created by running\n'
- 'a python program named neewpartreqnumgen.py\n'
- 'version ' + version + ' located in\n'
- "'S:\Parts Requisitions\Electrical Requests\' \n"
- 'created by Casey Hancock.\n')
- ## close the file
- placeholderfile.close()
- ## print out the file name so people know which request number is
- ## theirs.
- print(filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement