Last active
August 10, 2017 23:42
-
-
Save schmohlio/536da1f4e62f8c1c582947bff1405493 to your computer and use it in GitHub Desktop.
Prepend text to files matching pattern in current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import os | |
from os.path import join | |
TEXT = """syntax = "proto2"\n""" | |
def main(): | |
for dirpath, _, files in os.walk("."): | |
for f in files: | |
if f.endswith(".proto"): | |
with file(join(dirpath, f), 'r') as original: data = original.read() | |
with file(join(dirpath, f), 'w') as modified: modified.write(TEXT + data) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment