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


当前回答

另一个GUI解决方案:WinHex。

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

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

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

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

其他回答

检查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。

除了编写一个完整的应用程序,我们Python人可以用四行实现任何大小的文件,在Windows和Linux上使用相同的代码片段(os.stat()行只是一个检查):

>>> f = open('myfile.txt','w')
>>> f.seek(1024-1) # an example, pick any size
>>> f.write('\x00')
>>> f.close()
>>> os.stat('myfile.txt').st_size
1024L
>>>

我在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($_)

最近,我正在寻找一种方法来创建一个具有空间分配的大型虚拟文件。所有的解看起来都很尴尬。最后,我刚刚启动了Windows中的DISKPART实用程序(从Windows Vista开始嵌入):

DISKPART
CREATE VDISK FILE="C:\test.vhd" MAXIMUM=20000 TYPE=FIXED

其中MAXIMUM是最终的文件大小,这里是20gb。