FCPXML全自动处理

额,为什么要写这段代码 因为工作的时候需要。。。

#include <iostream>
#include <string>
#include <filesystem>
#include <fstream>
using namespace std;
int main() {
    std::string address;
    std::cout << "enter the plugins address:" << std::endl;
    std::cin >> address;
    std::filesystem::path str(address);
    if (!exists(str))  //必须先检测目录是否存在才能使用文件入口.
    {
        std::cout << "address is not a directory!" << std::endl;
        return 1;
    }
    std::filesystem::directory_entry entry(str);  //文件入口;
    std::filesystem::directory_iterator list(str);
    //遍历路径下的文件(const directory是为了避免浪费性能)
    for (const std::filesystem::directory_entry& it : list)
    {
        if (it.path().extension() == ".fcpxml") 
        {
            ifstream inFile(it.path());
            const string p = it.path().string();
            if (!inFile) 
            {
                std::cerr << "无法打开文件" << std::endl;
                return 1;
            }
            ofstream outputFile("temp.fcpxml");
            // 逐行读取文件,修改符合要求的行中的内容,然后将改成需要修改的格式a
            std::string line;
            while (std::getline(inFile, line)) 
            {
                //检查该行是否包含特定字符串
                if (line.find("format") && line.find("name") && line.find("height") && line.find("width") != std::string::npos) {
                    // 如果该行包含特定字符串,则将其更改为所需的内容
                    int a = line.length() - 2;
                    line=line.insert(a, " colorSpace=\"1-1-1(Rec. 709)\"");
                    outputFile << line << endl;
                }
                else 
                {
                    outputFile << line << endl;
                }
            }
            inFile.close();
            outputFile.close();
            remove(p.c_str());
            int result=rename("temp.fcpxml", p.c_str());
            if (result == 0) 
            {
                std::cout << "文件已更改" << std::endl;
            }
            else 
            {
                std::cout << "文件更改失败" << std::endl;
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值