我有这样的文件:
- file1_a_etc.txt,
- file1_b_etc.txt
- file2_a_z.txt
- file2_b_z.txt
我想获取带有“a”的文件的大小,即 file2_a_z.txt 和 file1_a_etc.txt
我通过这种方式获得了大量文件,因此无法单独指定每个名称。
我是 C 语言的初学者。
我知道如何读取单个文件的大小。我正在 window 上工作。
#include <stdio.h>
#include <sys/stat.h> // For struct stat and stat()
struct stat attr;
void main()
{
if(stat("filename.txt", &attr) == 0)
{
float x;
x=(attr.st_size)/1048576.0; //1MB=1048576 bytes
printf("Filesize: %.2f MB", x);
}
else
{
// couldn't open the file
printf("Couldn't get file attributes...");
}
}
最佳答案
对于 Windows 控制台,有函数 _findfirst
。对于第一个参数,输入 *a*.txt
。
关于c - 在C中,有没有办法获取名称与字符串匹配的多个文件的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28601199/