2

I want to fill up the disk for a test which requires the disk storage to be full. For this, I found that I could use the command line with the following command: fsutil file createnew <filename> <filesize in bytes>. Combined with fsutil volume diskfree <disk> to find out how much space is currently available this is fine so far and it works for the use case.

Now I have the question, can I somehow combine these commands, so that it can be "automated" in a way, that I don't have to manually check for the free storage and create the file accordingly?

In short, can somehow combine the output from fsutil volume diskfree with the input of fsutil file createnew to create a file that fills up the disk? Does a "one-liner" solution in cmd (or alternatively power shell) exist for this task?

OS in question is Win10 Enterprise.

0

3 Answers 3

9

The following powershell command get the free space of the disk using WMI then use fsutil to create the newfile. Don't forget to change the volume name if it's necessary.

$space = $(get-WmiObject win32_logicaldisk | where-object -Property DeviceID -EQ "C:" | select -ExpandProperty FreeSpace) ; fsutil file createNew yourFileName $space
2
  • Exactly what I needed. Works flawlessly. Thanks a lot! Commented Feb 1, 2021 at 14:12
  • It's worth noting that you'll get a Not enough space error in fsutil if you're filling a FAT32 drive and $space is above 4 GB (due to the max file size allowed).
    – virtualdj
    Commented Dec 30, 2021 at 10:49
1

It is really easy , you can do using this command on cmd:

for /F %C in ('wmic logicaldisk C: Get FreeSpace ^| find /V "FreeSpace" ^|find /I " "') do fsutil file createnew q %C

Creates a file named q in the current cmd directory (default C:\Windows\system32), file size equal to free space of drive C:

0

You can use this command to get the free space of the C:\ drive and then send the output to a file named freespace.txt after that it uses FOR to convert D into a variable and then uses fsutil to create a file named spacefiller that fills up the hard drive. the freespace.txt and spacefiller can be changed to anything you want, as long as you change them in both of the spots.

WMIC LOGICALDISK C: GET FreeSpace | find /V "FreeSpace" > freespace.txt & for /f %L in (freespace.txt) do fsutil file CreateNew spacefiller %L

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .