与在Linux系统上快速创建大文件相同, 我想在Windows系统上快速创建一个大文件。大的我想是5gb。内容并不重要。内置命令或短批处理文件将是更可取的,但如果没有其他简单的方法,我将接受应用程序。
当前回答
我一直在寻找一种方法来生成包含数据的大文件,而不仅仅是稀疏文件。遇到下面的技巧:
如果您想要创建一个包含真实数据的文件,那么您可以使用下面的命令行脚本。 这只是一个示例行追加创建一个大文件.." > dummy.txt /L %i in (1,1,14) do type dummy.txt >> dummy.txt (依次运行以上两个命令,或者可以将它们添加到批处理文件中。) 上面的命令在几秒钟内创建一个1mb的文件dummy.txt…
其他回答
普通的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);
}
我对所选答案中提到的相同fsutil方法做了一些补充。 这是为了创建许多不同扩展名和/或不同大小的文件。
set file_list=avi bmp doc docm docx eps gif jpeg jpg key m4v mov mp4 mpg msg nsf odt pdf png pps ppsx ppt pptx rar rtf tif tiff txt wmv xls xlsb xlsm xlsx xps zip 7z
set file_size= 1
for %%f in (%file_list%) do (
fsutil file createnew valid_%%f.%%f %file_size%
) > xxlogs.txt
代码可以从https://github.com/iamakidilam/bulkFileCreater.git克隆
我一直在寻找一种方法来生成包含数据的大文件,而不仅仅是稀疏文件。遇到下面的技巧:
如果您想要创建一个包含真实数据的文件,那么您可以使用下面的命令行脚本。 这只是一个示例行追加创建一个大文件.." > dummy.txt /L %i in (1,1,14) do type dummy.txt >> dummy.txt (依次运行以上两个命令,或者可以将它们添加到批处理文件中。) 上面的命令在几秒钟内创建一个1mb的文件dummy.txt…
快速执行还是在键盘上快速输入?如果你在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($_)
推荐文章
- 我如何找到哪个程序正在使用端口80在Windows?
- 在Windows中有像GREP这样的模式匹配实用程序吗?
- 如何在Windows命令提示符下运行.sh ?
- 如何从命令行在windows中找到mysql数据目录
- 在没有事件源注册的情况下写入Windows应用程序事件日志
- Windows FINDSTR命令的未记录的特性和限制是什么?
- 无法在Windows上从/usr/local/ssl/openssl.cnf加载配置信息
- 用Windows任务调度器运行批处理文件
- GIT克隆在windows中跨本地文件系统回购
- 如何运行一个PowerShell脚本而不显示窗口?
- PowerShell:仅为单个命令设置环境变量
- 为什么这个Windows批处理文件只执行第一行,而在命令shell中执行所有三行?
- 如何将文件内容读入批处理文件中的变量?
- 环境变量存储在Windows注册表的哪里?
- 有一个好的Valgrind Windows的替代品吗?