Skip to content

Instantly share code, notes, and snippets.

@attomos
Created August 25, 2013 04:18
Show Gist options
  • Select an option

  • Save attomos/6331976 to your computer and use it in GitHub Desktop.

Select an option

Save attomos/6331976 to your computer and use it in GitHub Desktop.
Prepend files in current directory with specified text. I used this Gist to prepend my imported blog (markdown files) to serve with Jekyll.
#!/usr/bin/env python
# encoding: utf-8
import os
text_to_prepend = '# encoding: utf-8'
for root, dirs, files in os.walk('./'):
for f in files:
if f != 'prepend.py':
with file(f, 'r') as original:
data = original.read()
with file(f, 'w') as modified:
modified.write(text_to_prepend + '\n' + data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment