- Published on
Create Test files with different sizes in windows
- Authors
- Name
- Jeevan Wijerathna
- @iamjeevanvj
Using fsutil command
To create a 10MB file using
fsutil
-
Open the Command Prompt by typing "cmd" in the search bar and selecting the "Command Prompt" app.
-
Use the
command with thefsutil
option, specifying the desired file size in bytes.file createnew
fsutil file createnew C:\\path\\to\\example.txt 10485760
The size specified is in bytes. In this case, 10MB is equivalent to 10,485,760 bytes (1024 bytes = 1KB, and 1024KB = 1MB).
-
Replace
with the actual path and filename where you want to create the file."C:\\path\\to\\example.txt"
After executing the command, a file named "example.txt" will be created with a size of 10MB at the specified location.
Please note that
fsutil
Using PowerShell
PowerShell code to create a file of a specific size:
powershellCopy code # Specify the file path and size $filePath = "C:\path\to\example.txt" $fileSizeInBytes = 1GB # Change this value to the desired file size # Create the file $fileStream = [System.IO.File]::Create($filePath) $fileStream.SetLength($fileSizeInBytes) $fileStream.Close()
In this code, we use the [System.IO.File]::Create()
SetLength()
"C:\path\to\example.txt"
$fileSizeInBytes