因此,我创建了一个用于合并文件的 c++ 可执行文件。我有 43 个文件,每个文件大小为 100MB。所以总共大约4.3GB。
两种情况:
一:如果文件名是1、2、3、4、5、6、...、43,大约需要2分钟完成合并。
二:如果文件名是This File.ova0, This File.ova1, ..., This File.ova42 大约需要7分钟才能完成合并。
这是同一个文件,我只是重命名了文件。知道有什么问题吗?
这是c++代码
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "boost/filesystem.hpp"
namespace bfs = boost::filesystem;
#pragma warning(disable : 4244)
typedef std::vector<std::string> FileVector;
int main(int argc, char **argv)
{
int bucketSize = 3024 * 3024;
FileVector Files;
//Check all command-line params to see if they exist..
for(int i = 1; i < argc; i++)
{
if(!bfs::exists(argv[i]))
{
std::cerr << "Failed to locate required part file: " << argv[i] << std::endl;
return 1;
}
//Store this file and continue on..
std::cout << "ADDING " << argv[i] << std::endl;
Files.push_back(argv[i]);
}
//Prepare to combine all the files..
FILE *FinalFile = fopen("abc def.ova", "ab");
for(int i = 0; i < Files.size(); i++)
{
FILE *ThisFile = fopen(Files[i].c_str(), "rb");
char *dataBucket = new char[bucketSize];
std::cout << "Combining " << Files[i].c_str() << "..." << std::endl;
//Read the file in chucks so we do not chew up all the memory..
while(long read_size = (fread(dataBucket, 1, bucketSize, ThisFile)))
{
//FILE *FinalFile = fopen("abc def.ova", "ab");
//::fseek(FinalFile, 0, SEEK_END);
fwrite(dataBucket, 1, read_size, FinalFile);
//fclose(FinalFile);
}
delete [] dataBucket;
fclose(ThisFile);
}
fclose(FinalFile);
return 0;
}
我通过 .bat 文件运行它,如下所示:
@ECHO OFF
Combiner.exe "This File.ova0" "This File.ova1" "This File.ova2"
PAUSE
或者
@ECHO OFF
Combiner.exe 1 2 3
PAUSE
两个.bat文件都到文件名末尾,我这里只写了3个文件,否则会太长
谢谢