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


当前回答

检查Windows Server 2003资源工具包工具。有一个名为Creatfil的实用程序。

 CREATFIL.EXE
 -? : This message
 -FileName -- name of the new file
 -FileSize -- size of file in KBytes, default is 1024 KBytes

它类似于Solaris上的mkfile。

其他回答

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

我在http://www.scribd.com/doc/445750/Create-a-Huge-File上找到了一个使用DEBUG的解决方案,但我不知道一个简单的方法来编写它,它似乎不能创建大于1gb的文件。

临时文件应该存储在Windows临时文件夹中。根据Rod的回答,您可以使用下面的一行代码创建一个5 GB的临时文件,该文件返回文件名

[System.IO.Path]::GetTempFileName() | % { [System.IO.File]::Create($_).SetLength(5gb).Close;$_ } | ? { $_ }

解释:

[System.IO.Path]::GetTempFileName() generates a random filename with random extension in the Windows Temp Folder The Pipeline is used to pass the name to [System.IO.File]::Create($_) which creates the file The file name is set to the newly created file with .SetLength(5gb). I was a bit surprised to discover, that PowerShell supports Byte Conversion, which is really helpful. The file handle needs to be closed with .close to allow other applications to access it With ;$_ the filename is returned and with | ? { $_ } it is ensured that only the filename is returned and not the empty string returned by [System.IO.File]::Create($_)

我一直在寻找一种方法来生成包含数据的大文件,而不仅仅是稀疏文件。遇到下面的技巧:

如果您想要创建一个包含真实数据的文件,那么您可以使用下面的命令行脚本。 这只是一个示例行追加创建一个大文件.." > dummy.txt /L %i in (1,1,14) do type dummy.txt >> dummy.txt (依次运行以上两个命令,或者可以将它们添加到批处理文件中。) 上面的命令在几秒钟内创建一个1mb的文件dummy.txt…

我需要一个普通的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。