SHOW:
|
|
- or go back to the newest paste.
1 | ||
2 | from datetime import date | |
3 | import glob | |
4 | import os | |
5 | ||
6 | ## Set version number. | |
7 | version = '1.0' | |
8 | ## Get the current date. | |
9 | now = date.today() | |
10 | ## Format it. | |
11 | today = now.strftime("%m-%d-%y") | |
12 | ## Set request type. May be improved by making it interactive later. | |
13 | request = 'Parts' | |
14 | ## Get to the parts request directory. | |
15 | os.chdir('S:\\Parts Requisitions\\Electrical Requests\\2013') | |
16 | ## Make a list of the filenames that start with a number and end with | |
17 | ## ".pdf". | |
18 | filelist = glob.glob('[0-99999]*.pdf') | |
19 | ## Sort the list so that the newest request filename is the first index. | |
20 | filelist.sort(reverse=True) | |
21 | ## Pull out the last requests filename. | |
22 | lastreq = filelist[0] | |
23 | ## Parse out the different parts of the file name. | |
24 | templist = lastreq.split() | |
25 | ## Pull out the portion of the file name that contains the number. | |
26 | lastnum = templist[0] | |
27 | ## Change the string into a integer. | |
28 | lastnum = int(lastnum) | |
29 | ## Increment the number by 1. | |
30 | newnum = lastnum + 1 | |
31 | ## Concatenate the parts of the new request file name into a single | |
32 | ## string | |
33 | filename = str(newnum) + ' ' + request + ' ' + today + ".pdf" | |
34 | ## Open a writable file with the proper file name. | |
35 | placeholderfile = open(filename, 'w') | |
36 | ## Place a summary of how the file was created in the file as plain | |
37 | ## text for anyone who wants to know more. | |
38 | placeholderfile.write('This is a placeholder file for the next parts\n' | |
39 | 'request number in line created by running\n' | |
40 | 'a python program named neewpartreqnumgen.py\n' | |
41 | 'version ' + version + ' located in\n' | |
42 | "'S:\Parts Requisitions\Electrical Requests\' \n" | |
43 | 'created by Casey Hancock.\n') | |
44 | ## close the file | |
45 | placeholderfile.close() | |
46 | ## print out the file name so people know which request number is | |
47 | ## theirs. | |
48 | print(filename) |