This project is implemented as a C++ library rather than a standalone command-line application. It provides reusable functions that can be linked into another program.
The library includes:
- directory traversal(recursive) with file metadata collection
- file count and total byte-size computation
- ascending sort by file size
- maximum file size lookup
- filename-based search
- line count for text files
- file name lookup
- file size lookup
- file list access
- Compiler: A C++17-compatible compiler
- Standard library: Support for
<filesystem>
-
Compile the implementation file into an object file:
g++ -std=c++17 -c main.cpp -o libcvault.o
-
Then link it with your application source:
g++ -std=c++17 my_app.cpp libcvault.o -o my_app
-
To create a static library:
ar rcs libcvault.a libcvault.o
Include the header:
#include "head.hpp"int populateData(const char* path);
Loads file names and sizes from the given directory into the library's internal list. The scanning is recursive in nature.
Important
The directory scanning bypasses restricted system folders to prevent unhandled filesystem errors.
Return values:
- `0` - success
- `-1` - path does not exist
- `-2` - path is not a directory
- `-3` - filesystem error
- `-4` - unknown error
-
long long int getTotalBytes();
Returns the total byte size of all files loaded by the last successfulpopulateDatacall. -
int getFileCount();
Returns the number of files currently loaded. -
void sortFileOnByte();
Sorts the loaded file list in ascending order based on size. -
long long int maxFile();
Returns the maximum loaded file size, or-1if no files are loaded. -
void sortFileOnName();
Sorts the loaded file list alphabetically by file name. -
long long int searchFile(const char* fname);
Searches the loaded file list by filename, returning the file size if found or-3if not found. -
long int lineCount(const char* filepath);
Returns the number of lines in the specified file, or-1if the file cannot be opened. -
const char* getFileName(int index);
Returns the name of the file present at a given index. -
long long int getFileSize(int index);
Returns the size(bytes) of the file present at a given index. -
const fileStructure* getFiles(size_t* out_count);Returns a raw pointer to the internal memory buffer of the file list when provided with the file count.