额,为什么要写这段代码 因为工作的时候需要。。。
#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;
}
}
}
}