How can I find the size of all files located inside a folder?

How about letting OS do it for you: long long int getFolderSize(string path) { // command to be executed std::string cmd(“du -sb “); cmd.append(path); cmd.append(” | cut -f1 2>&1″); // execute above command and get the output FILE *stream = popen(cmd.c_str(), “r”); if (stream) { const int max_size = 256; char readbuf[max_size]; if (fgets(readbuf, max_size, … Read more

2GB limit on file size when using fwrite in C?

On a 32 bits system (i.e. the OS is 32 bits), by default, fopen and co are limited to 32 bits size/offset/etc… You need to enable the large file support, or use the *64 bits option: http://www.gnu.org/software/libc/manual/html_node/Opening-Streams.html#index-fopen64-931 Then your fs needs to support this, but except fat and other primitive fs, all of them support … Read more

How do I “normalize” a pathname using boost::filesystem?

Boost v1.48 and above You can use boost::filesystem::canonical: path canonical(const path& p, const path& base = current_path()); path canonical(const path& p, system::error_code& ec); path canonical(const path& p, const path& base, system::error_code& ec); http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/reference.html#canonical v1.48 and above also provide the boost::filesystem::read_symlink function for resolving symbolic links. Boost versions prior to v1.48 As mentioned in other answers, … Read more

How to use to find files recursively?

There are a couple of ways: pathlib.Path().rglob() Use pathlib.Path().rglob() from the pathlib module, which was introduced in Python 3.5. from pathlib import Path for path in Path(‘src’).rglob(‘*.c’): print(path.name) glob.glob() If you don’t want to use pathlib, use glob.glob(): from glob import glob for filename in glob(‘src/**/*.c’, recursive=True): print(filename) For cases where matching files beginning with … Read more