DirectoryPrinterPro v1.0.0
Print your directory, with customization options.
Loading...
Searching...
No Matches
main.cpp File Reference
#include <chrono>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <unordered_set>
#include <vector>
#include "include/CLI11.hpp"
#include "include/termstyle.hpp"

Functions

bool checkIgnore (const fs::path &path)
 Check if the file should be ignored.
 
std::string subtractPath (const fs::path &path, const fs::path &base)
 Subtract the base path from the given path.
 
std::string addSpaces (int depth, bool isEnd)
 Add spaces to the output based on the depth and if it's the end of the branch.
 
void print (std::string str)
 Print the string to the console and the file if the flag is set.
 
void printDir (const fs::path &path, const std::unordered_set< std::string > &ignoreFiles, int maxDepth, int depth)
 Print the directory tree.
 
void initFile ()
 Initialize the output file.
 
void termstyle_init ()
 Initialize the termstyle presets.
 
int main (int argc, char *argv[])
 Main function.
 

Variables

const std::string outFile = "dir_tree.txt"
 Default output file.
 
std::ofstream file
 Output file stream.
 
bool no_ignore = false
 Flag to ignore files.
 
bool to_file = false
 Flag to output to a file.
 
bool use_prev_cmd = false
 Flag to use the previous command.
 
int maxDepth = -1
 Default recursion depth (-1 means infinite)
 
std::string dirName = ""
 Default directory name.
 
std::unordered_set< std::string > ignoreFiles
 Files to ignore.
 
std::unordered_set< std::string > noContent
 Directories to ignore contents.
 

Function Documentation

◆ addSpaces()

std::string addSpaces ( int depth,
bool isEnd )

Add spaces to the output based on the depth and if it's the end of the branch.

Parameters
depthThe depth of the current directory.
isEndTrue if it's the end of the branch, false otherwise.
Returns
The string with the spaces.

◆ checkIgnore()

bool checkIgnore ( const fs::path & path)

Check if the file should be ignored.

See also
ignoreFiles
no_ignore
Parameters
pathThe path to the file.
Returns
True if the file should be ignored, false otherwise.

◆ initFile()

void initFile ( )

Initialize the output file.

If the flag is set, the file will be created or truncated if it is already present.

Returns
void

◆ main()

int main ( int argc,
char * argv[] )

Main function.

Parameters
argcThe number of command line arguments.
argvThe command line arguments.
Returns
0 if the program executed successfully, 1 otherwise.

◆ print()

void print ( std::string str)

Print the string to the console and the file if the flag is set.

See also
to_file
Parameters
strThe string to print.
Returns
void

◆ printDir()

void printDir ( const fs::path & path,
const std::unordered_set< std::string > & ignoreFiles,
int maxDepth,
int depth )

Print the directory tree.

Parameters
pathThe path to the directory.
ignoreFilesThe files to ignore.
maxDepthThe maximum depth of recursion.
depthThe current depth of recursion. Default should be 1.
Returns
void

◆ subtractPath()

std::string subtractPath ( const fs::path & path,
const fs::path & base )

Subtract the base path from the given path.

subtractPath("/home/user/file.txt", "/home/user") -> "file.txt"

Parameters
pathThe path to subtract from.
baseThe base path.

◆ termstyle_init()

void termstyle_init ( )

Initialize the termstyle presets.

Returns
void