Share via

Creating large test file on Windows

gsndev 21 Reputation points
2021-07-28T19:04:26.207+00:00

I'm planning to monitor the network with a large file transfer and need to create a dummy test file on Windows. Please can I get a confirmation if creating a test file using fsutil is recommended for this task?
fsutil file createnew pathfilename size

Windows development | Windows API - Win32

Answer accepted by question author
  1. Andreas Baumgarten 131.5K Reputation points MVP Volunteer Moderator
    2021-07-28T19:58:54.54+00:00

    Hi @gsnarendran-4128 ,

    fsutil is a good option to create a large file.

    I am using the following script for the same task:

    $file = new-object System.IO.FileStream c:\temp\testfile.bin, Create, ReadWrite
    $file.SetLength(4GB)
    $file.Close()
    

    if you prefer a file with random content you can this this:

    $file = "c:\temp\testfile3.bin"
    $sizeInMB = 8
    $out = new-object byte[] ($sizeInMB*1048576); (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes($file, $out)
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. NetoMeter 6 Reputation points
    2021-07-28T20:18:55.567+00:00

    I like Andreas' solution as nowadays, using PS is the preferred approach. There is nothing wrong with using fsutil - you will have to specify the size in bytes though:

    fsutil file createNew C:\Temp\testfile.bin 4294967296

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.