简体   繁体   English

C ++比较2个文件夹中的文件

[英]C++ Comparing files in 2 folders

I am generating hashes for the contents of two folders. 我正在为两个文件夹的内容生成哈希。 I then want to compare all the hashes, one at a time of folder a to all the contents of folder b. 然后,我想比较所有哈希,一次将文件夹a与文件夹b的所有内容进行比较。

If they have equal files in each this works ok but I plan on having around 500 files in folder B and maybe 5-10 in folder A. the loop im using at the minute is as follows 如果它们每个文件都相等,则可以,但是我计划在文件夹B中容纳大约500个文件,在文件夹A中容纳5-10个文件。目前使用的循环即时消息如下

for (i=0;i<nbfiles1;i++)
{
    printf("file1: %s\n", files1[i]);
    for (j=0;j<nbfiles2;j++)
    {
        printf("    file2: %s\n", files2[j]);
        cs=ph_audio_distance_ber(hashes[i],lens[i],hashes2[j],lens2[j],threshold,block_size,Nc);
        double max_f = 0.0;
        for (index=0;index<Nc;index++)
        {
            if (cs[index] > max_f)
                max_f = cs[index];
        }//end if
        printf("    cs = %f\n", max_f);
    }//end for
}//end for

where nbfiles1 is the number of files in folder A and nbfiles 2 is the number of files in folder B 其中nbfiles1是文件夹A中的文件数,nbfiles 2是文件夹B中的文件数

The loop works fine if there are equal numbers of files in each but if there is an unequal number then it crashes. 如果每个文件中的文件数相等,则循环工作正常,但是如果文件数不相等,则崩溃。 I know the answer is staring right at me but after 3 hours of looking it hasnt dawned on me where im going wrong. 我知道答案正盯着我,但经过3个小时的观察,我还没有意识到我错了。

A std::bad_alloc exception is raised when you don't have enouth memory, or try to allocate an invalid size. 当您没有足够的内存或尝试分配无效的大小时,会引发std :: bad_alloc异常。 Check your code where memory allocations are done, and show us more if you don't find. 检查完成内存分配的代码,如果找不到,向我们显示更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM