与在Linux系统上快速创建大文件相同, 我想在Windows系统上快速创建一个大文件。大的我想是5gb。内容并不重要。内置命令或短批处理文件将是更可取的,但如果没有其他简单的方法,我将接受应用程序。
当前回答
查看RDFC http://www.bertel.de/software/rdfc/index-en.html
RDFC可能不是最快的,但它确实可以分配数据块。最快的方法必须使用较低级别的API来获取集群链,并将它们放入MFT中,而不写入数据。
注意,这里没有银弹-如果“创建”立即返回,这意味着你得到了一个稀疏文件,它只是一个假的大文件,但你不会得到数据块/链,直到你写入它。如果你只是阅读,你会得到非常快的零,这可能会让你相信你的驱动器突然变得非常快:-)
其他回答
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;
}
fsutil file createnew <filename> <length>
其中<length>为字节单位。
例如,要创建一个名为'test'的1MB (Windows MB或MiB)文件,可以使用这段代码。
fsutil file createnew test 1048576
但是Fsutil需要管理权限。
快速执行还是在键盘上快速输入?如果你在Windows上使用Python,你可以尝试这样做:
cmd /k py -3 -c "with open(r'C:\Users\LRiffel\BigFile.bin', 'wb') as file: file.truncate(5 * 1 << 30)"
临时文件应该存储在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人可以用四行实现任何大小的文件,在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
>>>
推荐文章
- 无法在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下记不住我的密码