与在Linux系统上快速创建大文件相同, 我想在Windows系统上快速创建一个大文件。大的我想是5gb。内容并不重要。内置命令或短批处理文件将是更可取的,但如果没有其他简单的方法,我将接受应用程序。


当前回答

在C:\Temp中创建一个文件来填充磁盘C:只留下10 MB:

[io.file]::Create("C:\temp\bigblob.txt").SetLength((gwmi Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace - 10MB).Close

其他回答

打开Windows任务管理器,右键单击正在运行的最大进程,然后单击“创建转储文件”。

这将在临时文件夹中创建一个相对于内存中进程大小的文件。

您可以轻松地创建一个千兆字节大小的文件。

您可以使用Sysinternals Contig工具。它有一个-n开关,用于创建一个给定大小的新文件。与fsutil不同,它不需要管理特权。

... 在几秒钟内生成1mb文件dummy.txt。

echo "This is just a sample line appended to create a big file.. " > dummy.txt 
for /L %i in (1,1,14) do type dummy.txt >> dummy.txt

请看这里:http://www.windows-commandline.com/how-to-create-large-dummy-file/

我需要一个普通的10gb文件进行测试,所以我不能使用fsutil,因为它创建稀疏文件(感谢@ZXX)。

@echo off

:: Create file with 2 bytes
echo.>file-big.txt

:: Expand to 1 KB
for /L %%i in (1, 1, 9) do type file-big.txt>>file-big.txt

:: Expand to 1 MB
for /L %%i in (1, 1, 10) do type file-big.txt>>file-big.txt

:: Expand to 1 GB
for /L %%i in (1, 1, 10) do type file-big.txt>>file-big.txt

:: Expand to 4 GB
del file-4gb.txt
for /L %%i in (1, 1, 4) do type file-big.txt>>file-4gb.txt

del file-big.txt

我想创建一个10gb的文件,但出于某种原因,它只显示为4gb,所以我想安全起见,停止在4gb。如果您真的想确保您的文件能够被操作系统和其他应用程序正确处理,请停止将其扩展到1gb。

另一个GUI解决方案:WinHex。

“File” > “New” > “Desired file size” = [X]
“File” > “Save as” = [Name]

与一些已经提出的解决方案相反,它实际上是在设备上写入(空)数据。

它还允许用可选择的模式或随机数据填充新文件:

“Edit” > “Fill file” (or “Fill block” if a block is selected)