Guest User

Untitled

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