sophuwu.site > crls
fixed file permission error
sophuwu sophie@sophuwu.site
Tue, 07 Nov 2023 22:05:57 +0100
commit

7e15d1a83528e62486a771f15c4f3f6b11d35eff

parent

55c91f90eca783dae4d5df6f4e570098c697a580

1 files changed, 14 insertions(+), 8 deletions(-)

jump to
M main.cppmain.cpp

@@ -96,6 +96,7 @@ std::string str() {return size + name + "\n";}

}; std::string convsize(unsigned long n) { + if (n == 0) return " 0.00 "; double f = n; char c[] = " KMGT"; unsigned long i = 0;

@@ -115,14 +116,19 @@ diritem item;

item.name = entry.path().filename().string(); len += item.name.length(); i++; - if (std::filesystem::is_directory(entry.path())) { - item.name += "/"; - item.size = "Folder "; - folders.push_back(item); - continue; - } else if (std::filesystem::exists(entry.path())) - item.size = convsize(std::filesystem::file_size(entry.path())); - else item.size = convsize(0); + try { + if (std::filesystem::is_directory(entry.path())) { + item.name += "/"; + item.size = "Folder "; + folders.push_back(item); + continue; + } + if (std::filesystem::exists(entry.path()) && std::filesystem::is_regular_file(entry.path())) + item.size = convsize(std::filesystem::file_size(entry.path())); + else item.size = convsize(0); + } catch (std::exception& e) { + item.size = " 0.00 "; + } files.push_back(item); } len /= i;