Filename.py

From UNB Archives and Special Collections
Revision as of 15:21, 7 May 2014 by ::1 (talk) (Created page with " #!/usr/local/bin/python # Opens a file, grabs its filename - appends it to the top of the file and inserts ENDTITLE after it. # Appends ENDPAGE at the end of the page. impo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  1. !/usr/local/bin/python
  1. Opens a file, grabs its filename - appends it to the top of the file and inserts ENDTITLE after it.
  2. Appends ENDPAGE at the end of the page.

import inspect, os from sys import argv

def line_prepender(filename,line):

   with open(filename,'r+') as f:
       content = f.read()
       f.seek(0,0)
       f.write(line.rstrip('\r\n') + '\n' + content)

def line_appender(filename,line): with open(filename, "a") as f: f.write(line)

script, filename = argv filetoOpen = open(filename) fileName = filetoOpen.name file = fileName.split("_")[0] lineattop = file + "\n" + "