• 使用powershell批量添加Qt的文件(生成pro)


    想使用QtCreator作为编辑器编辑keil或者IAR的工程,需要生成.pro文件,于是使用powershell批量处理。

     

     源码如下:

    $incPath = dir -filter "*.h" -Recurse
    $headList="",""
    $pathList = "",""
    
    
    foreach($fpath in $incPath)
    {
        $headList+=$fpath.DirectoryName + "/" + $fpath.name
        $headList = $headList -replace "\","/" 
    }
    
    foreach($fpath in $incPath)
    {
        $pathList += $fpath.DirectoryName
        $pathList = $pathList -replace "\","/" 
    }
    
    $txtTemp=$headList[0]
    
    $QtProHeadFileOut="HEADERS  +="
    $QtIncludePath = "INCLUDEPATH +="
    
    $workDir=get-location
    $proName = gi $workDir
    $workDir =$workDir -replace "\","/"
    $workDir += "/"
    
    $flag = 0
    
    foreach($txt in $pathList)
    {
        if($txt -ne $pathList[0])
        {
            if($txt -ne $txtTemp)
            { 
                $txtTemp=$txt    
                
                if($flag -eq 0)
                {
                    $flag = 1
                    $txt = $txt -replace $workDir , " "
                }
                else
                {
                    $txt = $txt -replace $workDir , "               "
                }
                
                $t = $pathList[-1] -replace $workDir , "               "
                if($txt -ne $t)
                {
                    $QtIncludePath += $txt + "\`n"
                }
                else
                {
                    $QtIncludePath += $txt + "`n`n"
                }
            }    
        }    
    }
    
    $flag = 0
    foreach($txt in $headList)
    {
        if($txt -ne $headList[0])
        {
            if($flag -eq 0)
            {
                $flag = 1
                $QtProHeadFileOut += $txt -replace $workDir , " "
            }
            else
            {
                $QtProHeadFileOut += $txt -replace $workDir , "            "
            }
            
            if($txt -ne $headList[-1])
            {
                $QtProHeadFileOut += "\`n"
            }
            else
            {
                $QtProHeadFileOut +="`n`n"
            }
            
        }
    }
    
    
    $sourcePath = dir -filter "*.c" -Recurse
    $sourceList="",""
    
    foreach($fpath in $sourcePath)
    {
        $sourceList+=$fpath.DirectoryName + "/" + $fpath.name
        $sourceList = $sourceList -replace "\","/" 
    }
    
    $sourceTemp=$sourceList[0]
    
    $QtProSourceFileOut="SOURCES  +="
    
    $flag = 0
    
    foreach($txt in $sourceList)
    {
        if($txt -ne $sourceTemp)
        {
            if($flag -eq 0)
            {
                $flag = 1
                $QtProSourceFileOut += $txt -replace $workDir , " "
            }
            else
            {
                $QtProSourceFileOut += $txt -replace $workDir , "            "
            }
            
            if($txt -ne $sourceList[-1])
            {
                $QtProSourceFileOut += "\`n"
            }
            else
            {
                $QtProSourceFileOut +="`n`n"
            }
        }
    }
    
    $proString ="TARGET = " + $proName.name +"`nTEMPLATE = app`n`n"
    $outfile = $proString + $QtProSourceFileOut + $QtProHeadFileOut + $QtIncludePath
    $outfile | Out-File -Encoding ascii qt.pro

    最后会在工作目录生成一个qt.pro的文件。

    使用方法:

    1,打开powershell(win + R,输入powershell)

    2,粘贴上面代码

    3,回车,回车

    想要添加.cpp文件,只需要将 

    $sourcePath = dir -filter "*.c" -Recurse
    改成
    $sourcePath = dir -filter "*.cpp" -Recurse
    就可以了。
  • 相关阅读:
    HCIA_R&S-学习_Day05(PPPoE、DHCP、ACL、NAT)
    HCIA_R&S-学习_Day04(链路状态协议OSPF & PPP)
    HCIA_R&S-学习_Day03(路由协议基础与实现)
    【详谈 Delta Lake 】系列技术专题 之 湖仓一体( Lakehouse )
    工作7年,我的10条经验总结
    Hologres揭秘:优化COPY,批量导入性能提升5倍+
    谈谈JVM内部锁升级过程
    如何帮用户管好云账本?阿里云数据库助力收钱吧 | 甲子光年
    重磅 | 数据库自治服务DAS论文入选全球顶会SIGMOD,领航“数据库自动驾驶”新时代
    同程旅行基于 RocketMQ 高可用架构实践
  • 原文地址:https://www.cnblogs.com/WeyneChen/p/5571184.html
Copyright © 2020-2023  润新知