mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-01-14 08:28:03 -05:00
Merge pull request #500 from mikekaganski/master
Fix directory size calculations
This commit is contained in:
@@ -117,11 +117,12 @@
|
||||
{
|
||||
return (path == L"." || path == L"..");
|
||||
}
|
||||
inline unsigned long long CalculateDirSize(const std::wstring &path, std::vector<std::wstring> *errVect = NULL, unsigned long long size = 0)
|
||||
inline unsigned long long CalculateDirSize(const std::wstring &path, std::vector<std::wstring> *errVect = NULL)
|
||||
{
|
||||
WIN32_FIND_DATA data;
|
||||
unsigned long long size = 0;
|
||||
WIN32_FIND_DATAW data;
|
||||
HANDLE sh = NULL;
|
||||
sh = FindFirstFile((path + L"\\*").c_str(), &data);
|
||||
sh = FindFirstFileW((path + L"\\*").c_str(), &data);
|
||||
|
||||
if (sh == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
@@ -137,15 +138,15 @@
|
||||
if (!IsBrowsePath(data.cFileName))
|
||||
{
|
||||
// if found object is ...
|
||||
if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
|
||||
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
// directory, then search it recursievly
|
||||
size = CalculateDirSize(path + L"\\" + data.cFileName, NULL, size);
|
||||
size += CalculateDirSize(path + L"\\" + data.cFileName, NULL);
|
||||
else
|
||||
// otherwise get object size and add it to directory size
|
||||
size += (unsigned long long) (data.nFileSizeHigh * (MAXDWORD ) + data.nFileSizeLow);
|
||||
size += data.nFileSizeHigh * (unsigned long long)(MAXDWORD) + data.nFileSizeLow;
|
||||
}
|
||||
|
||||
} while (FindNextFile(sh, &data)); // do
|
||||
} while (FindNextFileW(sh, &data)); // do
|
||||
|
||||
FindClose(sh);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
|
||||
static double ftw_summer; // An evil global variable for the ftw function
|
||||
static thread_local unsigned long long ftw_summer; // An evil global variable for the ftw function
|
||||
int ftw_function(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf){
|
||||
ftw_summer += sb->st_size;
|
||||
return 0; /* To tell nftw() to continue */
|
||||
|
||||
Reference in New Issue
Block a user