Quickly create large file on a Windows system

前端 未结 23 2320
别那么骄傲
别那么骄傲 2020-12-07 06:35

In the same vein as Quickly create a large file on a Linux system, I\'d like to quickly create a large file on a Windows system. By large I\'m thinking 5 GB.

23条回答
  •  不思量自难忘°
    2020-12-07 07:12

    Plain ol' C... this builds under MinGW GCC on Windows XX and should work on any 'generic' C platform.

    It generates a null file of a specified size. The resultant file is NOT just a directory space-occupier entry, and in fact occupies the specified number of bytes. This is fast because no actual writes occur except for the byte written before close.

    My instance produces a file full of zeros - this could vary by platform; this program essentially sets up the directory structure for whatever data is hanging around.

    #include 
    #include 
    
    FILE *file;
    
    int main(int argc, char **argv)
    {
        unsigned long  size;
    
        if(argc!=3)
        {
            printf("Error ... syntax: Fillerfile  size  Fname \n\n");
            exit(1);
        }
    
        size = atoi(&*argv[1]);
    
        printf("Creating %d byte file '%s'...\n", size, &*argv[2]);
    
        if(!(file = fopen(&*argv[2], "w+")))
        {
            printf("Error opening file %s!\n\n", &*argv[2]);
            exit(1);
        }
    
        fseek(file, size-1, SEEK_SET);
        fprintf(file, "%c", 0x00);
        fclose(file);
    }
    

提交回复
热议问题