与在Linux系统上快速创建大文件相同, 我想在Windows系统上快速创建一个大文件。大的我想是5gb。内容并不重要。内置命令或短批处理文件将是更可取的,但如果没有其他简单的方法,我将接受应用程序。
当前回答
Use:
/*
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;
}
其他回答
快速执行还是在键盘上快速输入?如果你在Windows上使用Python,你可以尝试这样做:
cmd /k py -3 -c "with open(r'C:\Users\LRiffel\BigFile.bin', 'wb') as file: file.truncate(5 * 1 << 30)"
可以使用cat powershell命令。
首先创建一个包含几个字符的简单文本文件。输入的初始字符越多,它变大的速度就越快。调用out。txt。然后在Powershell中:
cat out.txt >> out.txt
等待足够长的时间,使文件足够大。然后按ctrl-c结束它。
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()
检查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。
查看RDFC http://www.bertel.de/software/rdfc/index-en.html
RDFC可能不是最快的,但它确实可以分配数据块。最快的方法必须使用较低级别的API来获取集群链,并将它们放入MFT中,而不写入数据。
注意,这里没有银弹-如果“创建”立即返回,这意味着你得到了一个稀疏文件,它只是一个假的大文件,但你不会得到数据块/链,直到你写入它。如果你只是阅读,你会得到非常快的零,这可能会让你相信你的驱动器突然变得非常快:-)
推荐文章
- 无法在Windows上从/usr/local/ssl/openssl.cnf加载配置信息
- 用Windows任务调度器运行批处理文件
- GIT克隆在windows中跨本地文件系统回购
- 如何运行一个PowerShell脚本而不显示窗口?
- PowerShell:仅为单个命令设置环境变量
- 为什么这个Windows批处理文件只执行第一行,而在命令shell中执行所有三行?
- 如何将文件内容读入批处理文件中的变量?
- 环境变量存储在Windows注册表的哪里?
- 有一个好的Valgrind Windows的替代品吗?
- Windows和Linux上的c++编译:ifdef开关
- 如何验证批处理文件中是否存在一个文件?
- 如何循环通过文件匹配通配符在批处理文件
- 异步运行Windows批处理文件命令
- XAMPP -端口80被PID 4的“无法打开进程”使用!12
- 为什么git在Windows下记不住我的密码