与在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。
其他回答
临时文件应该存储在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($_)
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()
我一直在寻找一种方法来生成包含数据的大文件,而不仅仅是稀疏文件。遇到下面的技巧:
如果您想要创建一个包含真实数据的文件,那么您可以使用下面的命令行脚本。 这只是一个示例行追加创建一个大文件.." > dummy.txt /L %i in (1,1,14) do type dummy.txt >> dummy.txt (依次运行以上两个命令,或者可以将它们添加到批处理文件中。) 上面的命令在几秒钟内创建一个1mb的文件dummy.txt…
最近,我正在寻找一种方法来创建一个具有空间分配的大型虚拟文件。所有的解看起来都很尴尬。最后,我刚刚启动了Windows中的DISKPART实用程序(从Windows Vista开始嵌入):
DISKPART
CREATE VDISK FILE="C:\test.vhd" MAXIMUM=20000 TYPE=FIXED
其中MAXIMUM是最终的文件大小,这里是20gb。
可以使用cat powershell命令。
首先创建一个包含几个字符的简单文本文件。输入的初始字符越多,它变大的速度就越快。调用out。txt。然后在Powershell中:
cat out.txt >> out.txt
等待足够长的时间,使文件足够大。然后按ctrl-c结束它。
推荐文章
- 用Windows任务调度器运行批处理文件
- GIT克隆在windows中跨本地文件系统回购
- 如何运行一个PowerShell脚本而不显示窗口?
- PowerShell:仅为单个命令设置环境变量
- 为什么这个Windows批处理文件只执行第一行,而在命令shell中执行所有三行?
- 如何将文件内容读入批处理文件中的变量?
- 环境变量存储在Windows注册表的哪里?
- 有一个好的Valgrind Windows的替代品吗?
- Windows和Linux上的c++编译:ifdef开关
- 如何验证批处理文件中是否存在一个文件?
- 如何循环通过文件匹配通配符在批处理文件
- 异步运行Windows批处理文件命令
- XAMPP -端口80被PID 4的“无法打开进程”使用!12
- 为什么git在Windows下记不住我的密码
- Git克隆/拉不断冻结在“存储密钥在缓存?”