当前位置:首页 > python > 正文内容

python自动归类代码文件到vs工程筛选器(.vcxproj.filters)

xuwenyan12个月前 (12-16)python302
import sys
import os

def FromLineGetValue(line: str, head: str, tail: str) -> dict:
        pos = line.find(head)
        if pos == -1:
            return False, ''
        pos += len(head)
        pos1 = line.find(tail, pos)
        if pos1 == -1:
            return False, ''
        return True, line[pos:pos1]

if __name__ == '__main__':
    filter_file = 'path\\xxx.vcxproj.filters'
    filter_lines = []
    with open(filter_file, mode='r', encoding='utf-8') as f:
        lines = f.readlines()
        for line in lines:
            if line.find('/>') == -1:
                filter_lines.append(line)
                continue
            has, include = FromLineGetValue(line, 'Include="', '"')
            if not has or len(include) == 0:
                filter_lines.append(line)
                continue
            path = os.path.dirname(include)
            if len(path) == 0:
                filter_lines.append(line)
                continue
            if line.find('ClCompile') != -1:
                filter_lines.append('    <ClCompile Include="%s">\r' % include)
                filter_lines.append('        <Filter>%s</Filter>\r' % path)
                filter_lines.append('    </ClCompile>\r')
            else:
                filter_lines.append('    <ClInclude Include="%s">\r' % include)
                filter_lines.append('        <Filter>%s</Filter>\r' % path)
                filter_lines.append('     </ClInclude>\r')
        f.close()

    with open(filter_file, mode='w', encoding='utf-8') as f:
        f.writelines(filter_lines)
        f.close()
    sys.exit(0)


    文章作者:xuwenyan
    版权声明:本文为本站原创文章,转载请注明出处,非常感谢,如版权漏申明或您觉得任何有异议的地方欢迎与本站取得联系。

    扫描二维码推送至手机访问。

    版权声明:本文由艺文笔记发布,如需转载请注明出处。

    本文链接:https://www.xuwenyan.com/archives/2953

    标签: python编程
    分享给朋友:
    返回列表

    上一篇:如何获取python参数命令行

    没有最新的文章了...

    “python自动归类代码文件到vs工程筛选器(.vcxproj.filters)” 的相关文章

    python多进程与多线程分析与使用(二)

    python多进程与多线程分析与使用(二)

    1、使用多线程可以有效利用CPU资源,线程享有相同的地址空间和内存,这些线程如果同时读写变量,导致互相干扰,就会产生并发问题,为了避免并发问题,绝不能让多个线程读取或写入相同的变量,因此python中使用了全局锁(GIL),此锁只有一个,当某线程执行某个函数时,其他线程不能同时执行,直到锁被释放(...

    python多进程与多线程分析与使用(三)

    python多进程与多线程分析与使用(三)

    操作系统是可以并行运行多个任务的。比如你一边听歌,一边玩游戏一样。现在的cpu大都是多核的,但即使是过去的单核cpu也是支持多任务并行执行。   单核cpu执行多任务的原理:操作系统交替轮流地执行各个任务。先让任务1,一段时间后切到任务2、任务3...,这样往复地执行下去。由...

    python获取命令参数报错index out of range

    python获取命令参数报错index out of range

    python获取命令行参数的方法import sys sys.argv[index] // index is 0 1 2....报错index out of range大多数解决方案都是说你没有传递足够的参数,这是原因之一,但是...

    Python常用方法整理(路径、文件、编码格式等)

    Python常用方法整理(路径、文件、编码格式等)

    获得工作路径import os work_path = os.getcwd()设置工作路径import os os.chdir('d:\\test')获取脚本所在路径import os current_path =&n...

    如何获取python参数命令行

    如何获取python参数命令行

    如何获取python的命令行参数,如何解析参数,如下:command_line.pyclass CommandLine(object):     def __init__(self):     &...