是否有办法使用c标准库函数获取目录大小?如何使用c标准库获取目录大小
回答
你是什么意思的'目录的大小'?
- 这是包含在这个目录中的文件的总大小吗?
- ...再加上子目录的大小?
- 它是否仅与此目录中包含的文件数量相关联?
- ...加上子目录的数量?
- ...加上子目录本身的大小?
这些对于单个C库或系统调用都是不可能的。
+1。标准语言库不可能。 – DevSolar 2010-11-03 11:54:12
与一个C库系统调用。 +1 – 2010-11-03 12:41:10
不.C和C++标准库没有明确支持目录的概念。
就他们而言,“C:\ test \ test.txt”中的反斜杠没有特殊含义。这是OS要处理的。
这应该让你去。
对于Windows,请参阅: http://code.google.com/p/portaputty/source/browse/trunk/windows/dirent.c?r=8
或本: http://www.softagalleria.net/dirent.php
或只使用MinGW的编译器。
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h> // for opendir(), readdir(), closedir()
#include <sys/stat.h> // for stat()
dir_proc = opendir(PROC_DIRECTORY) ;
if (dir_proc == NULL)
{
perror("Couldn't open the " PROC_DIRECTORY " directory") ;
return (pid_t) -2 ;
}
// Loop while not NULL
while ((de_DirEntity = readdir(dir_proc)))
{
if (de_DirEntity->d_type == DT_DIR)
{
if (IsNumeric(de_DirEntity->d_name))
{
strcpy(chrarry_CommandLinePath, PROC_DIRECTORY) ;
strcat(chrarry_CommandLinePath, de_DirEntity->d_name) ;
strcat(chrarry_CommandLinePath, "/cmdline") ;
FILE* fd_CmdLineFile = fopen (chrarry_CommandLinePath, "rt") ; // open the file for reading text
if (fd_CmdLineFile)
{
fscanf(fd_CmdLineFile, "%s", chrarry_NameOfProcess) ; // read from /proc/<NR>/cmdline
fclose(fd_CmdLineFile); // close the file prior to exiting the routine
if (strrchr(chrarry_NameOfProcess, '/'))
chrptr_StringToCompare = strrchr(chrarry_NameOfProcess, '/') +1 ;
else
chrptr_StringToCompare = chrarry_NameOfProcess ;
//printf("Process name: %s\n", chrarry_NameOfProcess);
//printf("Pure Process name: %s\n", chrptr_StringToCompare);
if (CompareFunction(chrptr_StringToCompare, cchrptr_ProcessName, intCaseSensitiveness))
{
pid_ProcessIdentifier = (pid_t) atoi(de_DirEntity->d_name) ;
closedir(dir_proc) ;
return pid_ProcessIdentifier ;
}
}
}
}
}
closedir(dir_proc) ;
wtf?和另外6个 – 2010-11-03 14:56:09
@Matt Joiner:你是什么意思? – 2010-11-03 16:13:28
结账this post with regard to how to get the size of a file。您可能需要总结目录中文件的大小以获取“目录大小”。
如果您使用的是Linux,这些职位可能是你的兴趣:
- 1. 如何使用标准Python类获取图像大小(不使用外部库)?
- 2. 如何在OS X上使用Swift获取目录大小
- 3. 目标中的目录大小C
- 4. 如何获取目录大小,HTML5文件API,使用webkit目录
- 5. 如何在C#中获取目录大小(目录中的文件)?
- 6. 获取使用标准的Java库
- 7. 如何从C/C++获取virt大小?
- 8. 如何获取根目录下每个目录占用的大小?
- 9. 获取目录中文件的大小
- 10. PowerShell脚本获取目录总大小
- 11. 递归获取目录的大小
- 12. PHP - 获取目录的大小
- 13. 从.NET标准库中获取Windows系统目录
- 14. 如何使用boost库获取SAMPLE标准偏差?
- 15. 使用Java 7获取文件/目录大小新的IO
- 16. 使用du获取特定子目录的大小
- 17. C++:获取的所有文件的大小当前目录
- 18. 如何获取目录中文件的总计大小?
- 19. 如何在bash中获取多个目录的大小?
- 20. 如何获取C文件的大小?
- 21. C#项目标准目录布局
- 22. C++如何获取PNG文件的图像大小(在目录中)
- 23. 使用任务获取目录图标
- 24. 如何使用标准目录布局创建Maven项目?
- 25. 如何获取根的大小&&已使用的根的大小
- 26. 如何使用Java获取Ram大小和硬盘大小?
- 27. 如何使用ActionScript获取“%systemroot%”目录
- 28. 如何在C中使用malloc获取* char的大小?
- 29. 如何在Windows中使用C获取文件夹大小?
- 30. Python标准库,以获得总内存大小
请,请,如果你的意思是声明,“所有文件的总文件大小在此目录下“或”目录中的文件数量“。 – 2010-11-03 12:41:54
目录列表是OS特定的。 – ruslik 2010-11-03 13:29:50