是否有辦法使用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. SizeForItemAtIndexPath:獲取項目標準大小
- 2. 如何使用標準Python類獲取圖像大小(不使用外部庫)?
- 3. 獲取目錄大小
- 4. 如何在OS X上使用Swift獲取目錄大小
- 5. 如何獲取C中子目錄的總大小?
- 6. 目標中的目錄大小C
- 7. 如何獲取目錄大小,HTML5文件API,使用webkit目錄
- 8. 如何在C#中獲取目錄大小(目錄中的文件)?
- 9. 如何在postgresql中準確獲取數據庫大小?
- 10. 獲取使用標準的Java庫
- 11. 如何從C/C++獲取virt大小?
- 12. 如何獲取根目錄下每個目錄佔用的大小?
- 13. 從.NET標準庫中獲取Windows系統目錄
- 14. 獲取與門檻目錄大小
- 15. PHP - 獲取目錄的大小
- 16. 獲取目錄大小ssh2 php
- 17. PowerShell腳本獲取目錄總大小
- 18. Windows Phone - IsolatedStorage - 獲取目錄大小
- 19. 遞歸獲取目錄的大小
- 20. 獲取目錄中文件的大小
- 21. 如何使用boost庫獲取SAMPLE標準偏差?
- 22. 用於大數和小數的C++標準庫常量?
- 23. 使用du獲取特定子目錄的大小
- 24. 使用Java 7獲取文件/目錄大小新的IO
- 25. C++:獲取的所有文件的大小當前目錄
- 26. 如何獲取C文件的大小?
- 27. 如何獲取目錄中文件的總計大小?
- 28. 如何快速獲取目錄的大小?
- 29. 如何在bash中獲取多個目錄的大小?
- 30. C#項目標準目錄佈局
請,請,如果你的意思是聲明,「所有文件的總文件大小在此目錄下「或」目錄中的文件數量「。 – 2010-11-03 12:41:54
目錄列表是OS特定的。 – ruslik 2010-11-03 13:29:50