如何在 Windows 中生成确定大小的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/808005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Generate File of a determinate Size in Windows?
提问by Jedi Master Spooky
How is the Best and fastest way to do it?
最好和最快的方法是什么?
回答by mihi
PowerShell:
电源外壳:
$f = new-object System.IO.FileStream c:\temp\test.dat, Create, ReadWrite
$f.SetLength(42MB)
$f.Close()
This will create a file c:\temp\test.dat that consists of 42MB of nullbytes. You can of course just give byte count instead as well. (42MB = 42 * 1048576 for PowerShell)
这将创建一个包含 42MB 空字节的文件 c:\temp\test.dat。您当然也可以只提供字节数。(对于 PowerShell,42MB = 42 * 1048576)
回答by Jedi Master Spooky
I found this Page, I try it and work great.
我找到了这个页面,我尝试了一下,效果很好。
To create a single File use
创建单个文件使用
fsutil file createnew filename filesize
To create a lot of Files use
要创建大量文件,请使用
For /L %i in (1,1,25000) do fsutil file createnew A%i.tmp 12288
will create 25,000 files of 12288 bytes (12KB) named A1.tmp, A2.tmp, A3,tmp…
将创建 25,000 个 12288 字节 (12KB) 的文件,名为 A1.tmp、A2.tmp、A3、tmp…
回答by CB.
c:\>fsutil file createnew /?
Usage : fsutil file createnew <filename> <length>
Eg : fsutil file createnew C:\testfile.txt 1000