Quickly create large file on a Windows system

前端 未结 23 2376
别那么骄傲
别那么骄傲 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:10

    Use:

    /*
    Creates an empty file, which can take all of the disk
    space. Just specify the desired file size on the
    command line.
    */
    
    #include 
    #include 
    
    int main (int argc, char* ARGV[])
    {
        int size;
        size = atoi(ARGV[1]);
        const char* full = "fulldisk.dsk";
        HANDLE hf = CreateFile(full,
                               GENERIC_WRITE,
                               0,
                               0,
                               CREATE_ALWAYS,
                               0,
                               0);
        SetFilePointer(hf, size, 0, FILE_BEGIN);
        SetEndOfFile(hf);
        CloseHandle(hf);
        return 0;
    }
    

提交回复
热议问题