检查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的解决方案,但我不知道一个简单的方法来编写它,它似乎不能创建大于1 GB的文件。

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

使用:

/*
Creates an empty file, which can take all of the disk
space. Just specify the desired file size on the
command line.
*/


#include <windows.h>
#include <stdlib.h>


int main (int argc, char* ARGV[])
{
int size;
size = atoi(ARGV[1]);
const char* full = "fulldisk.dsk";
HANDLE hf = CreateFile(full,
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
0,
0);
SetFilePointer(hf, size, 0, FILE_BEGIN);
SetEndOfFile(hf);
CloseHandle(hf);
return 0;
}
fsutil file createnew <filename> <length>

其中<length>以字节为单位。

例如,要创建一个名为'test'的1MB (Windows MB或MiB)文件,可以使用此代码。

fsutil file createnew test 1048576

fsutil需要管理权限。

查看RDFC http://www.bertel.de/software/rdfc/index-en.html

RDFC可能不是最快的,但它确实可以分配数据块。最快的方法必须使用较低级别的API来获取集群链,并将它们放入分区,中而不写入数据。

注意,这里没有银弹-如果“创建”立即返回,这意味着你得到了一个稀疏文件,它只是一个假的大文件,但你不会得到数据块/链,直到你写入它。如果你只是阅读,你会得到非常快的零,这可能会让你相信你的驱动器突然变得非常快:-)

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

如果您想要创建一个包含真实数据的文件,那么您可以使用下面的命令行脚本。

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

(依次运行以上两个命令,或者可以将它们添加到批处理文件中。)

上面的命令在几秒钟内创建一个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。

我发现了一个很好的实用程序,可以在https://github.com/acch/genfiles中配置。

它用随机数据填充目标文件,因此使用稀疏文件没有问题,而且对于我的目的(测试压缩算法)来说,它提供了不错的白噪声水平。

Plain ol' C…这是在Windows XX上的MinGW GCC下构建的,应该可以工作

它生成一个指定大小的空文件。生成的文件不仅仅是一个目录空间占用者条目,而且实际上占用了指定数量的字节。这是快速的,因为除了在关闭前写入字节外,没有实际的写入发生。

我的实例生成一个全是0的文件-这可能因平台而异;这 程序本质上为挂起的任何数据设置目录结构 。< / p >
#include <stdio.h>
#include <stdlib.h>


FILE *file;


int main(int argc, char **argv)
{
unsigned long  size;


if(argc!=3)
{
printf("Error ... syntax: Fillerfile  size  Fname \n\n");
exit(1);
}


size = atoi(&*argv[1]);


printf("Creating %d byte file '%s'...\n", size, &*argv[2]);


if(!(file = fopen(&*argv[2], "w+")))
{
printf("Error opening file %s!\n\n", &*argv[2]);
exit(1);
}


fseek(file, size-1, SEEK_SET);
fprintf(file, "%c", 0x00);
fclose(file);
}

你可以试试下面的c++代码:

#include<stdlib.h>
#include<iostream>
#include<conio.h>
#include<fstream>
#using namespace std;


int main()
{
int a;
ofstream fcout ("big_file.txt");
for(;;a += 1999999999){
do{
fcout << a;
}
while(!a);
}
}

可能需要一些时间来生成,这取决于你的CPU速度…

Python中的简单回答:如果你需要创建一个大的真实文本文件,我只是使用了一个简单的while循环,并能够在大约20秒内创建一个5 GB的文件。我知道这很粗糙,但已经够快了。

outfile = open("outfile.log", "a+")


def write(outfile):
outfile.write("hello world hello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello world"+"\n")
return


i=0
while i < 1000000:
write(outfile)
i += 1
outfile.close()

... 在几秒钟内生成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/

打开Windows任务管理器,找到你正在运行的最大进程,右键单击,然后单击Create dump file

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

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

Enter image description here

Enter image description here

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

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

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

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

其中最大是生成的文件大小,这里是20gb。

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

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

解释:

  • [System.IO.Path]::GetTempFileName()在Windows Temp文件夹中生成一个随机扩展名的随机文件名
  • 该Pipeline用于将名称传递给创建文件的[System.IO.File]::Create($_)
  • 文件名设置为新创建的.SetLength(5gb)文件。我有点惊讶地发现,PowerShell支持字节转换,这是非常有用的。
  • 文件句柄需要用.close关闭,以允许其他应用程序访问它
  • 使用;$_返回文件名,使用| ? { $_ }确保只返回文件名,而不是[System.IO.File]::Create($_)返回的空字符串

快速执行还是在键盘上快速输入?如果你在Windows上使用Python,你可以尝试这样做:

cmd /k py -3 -c "with open(r'C:\Users\LRiffel\BigFile.bin', 'wb') as file: file.truncate(5 * 1 << 30)"
我已经对选定答案中提到的相同fsutil方法做了一些添加。 这是创建许多不同扩展名和/或各种大小的文件
set file_list=avi bmp doc docm docx eps gif jpeg jpg key m4v mov mp4 mpg msg nsf odt pdf png pps ppsx ppt pptx rar rtf tif tiff txt wmv xls xlsb xlsm xlsx xps zip 7z
set file_size= 1
for %%f in (%file_list%) do (
fsutil file createnew valid_%%f.%%f %file_size%
) > xxlogs.txt

代码可以从https://github.com/iamakidilam/bulkFileCreater.git克隆

我找到的最简单的方法是这个免费实用程序:http://www.mynikko.com/dummy/

创建任意大小的虚拟文件,其中填充了空格或填充了不可压缩的内容(由您选择)。这是一张截图:

enter image description here

另一个GUI解决方案:WinHex。

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

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

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

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

可以使用cat powershell命令。

首先创建一个包含几个字符的简单文本文件。输入的初始字符越多,它变大的速度就越快。调用out。txt。然后在Powershell中:

cat out.txt >> out.txt

等待足够长的时间,使文件足够大。然后按ctrl-c结束它。