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


当前回答

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

其他回答

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

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

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

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

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

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()

普通的C…这是在Windows XX上的MinGW GCC下构建的,应该可以工作 在任何“通用”C平台上。

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

我的实例生成了一个全是0的文件——这可能因平台而异;这 程序本质上为挂起的任何数据设置目录结构 周围。

#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);
}

另一个GUI解决方案:WinHex。

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

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

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

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