0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pythonで、CPPのヘッダ部分をかき集めてCSVに書く!

Posted at

こんな感じでパス設定すればOK

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import glob
import csv

if __name__ == '__main__':


    filelist=[]
    filelist.extend(glob.glob('./src/**/*.cpp', recursive=True))
    filelist.extend(glob.glob('./src/**/*.c', recursive=True))
    filelist.extend(glob.glob('./inc/**/*.hpp', recursive=True))
    filelist.extend(glob.glob('./inc/**/*.h', recursive=True))

    header_list=[]
    header_list.append(["src","line","include"])

    for filepath in filelist:
        print(filepath)
        with open(filepath, encoding='utf-8') as f:
            for i, line in enumerate(f):
                if '#include' in line:
                    line = line.replace('\n','')
                    header_list.append([filepath,str(i),line])


    with open('./sample_writer.csv', 'w') as f:
        writer = csv.writer(f)
        writer.writerows(header_list)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?