Coder Social home page Coder Social logo

cpp-file-manager's Introduction

CI

CPP-File-Manager

C++ File Manager allows you to list files in C++, ignore extensions (or just list specified extensions) and write the whole directory structure into a fancy tree-like structure which can be integrated in Markdown files. This is the first release. Please file issues with [FEATURE REQUEST] in the title, and we'll be happy to take a look at it.

The C++ File Manager provides the following functions to users:

  1. clear() - Clears the memory allocated to corePath.
  2. clear(std::string new_path) - Assigns a new path to the corePath variable.
  3. info() - Prints the corePath assigned to the FileManager object to the console.
  4. list_files(std::vector<std::string> extensions, bool ignore_extensions) - Lists the files and directories in corePath. The first argument is extensions which is a vector of file extensions to be ignored. These extensions are ignored only when the second argument i.e. ignore_extensions is set to true.
  5. writeToFile(std::vector<string> ignore_dirs, std::vector<std::string> ignore_extension) - Writes the tree structure for the files and directories in corePath into a .txt file. This functions iterates till the innermost files of all the directories. The first argument ignore_dirs contains a vector of directories to be ignored in the tree structures. Similarly, the second argument ignore_extensions contains a vector of files extensions to be ignored in the final tree structure.

Usage

Binary

The fmanager binary has the following options :

  -h  --help                        Print usage. 
  -p  --path filePath               Input path (to be iterated). 
  -l  --list_files                  Call the list files function. 
  -t  --tree                        Call the tree function. 
  -d --ignore_dirs dir1,dir2        Ignore dirs while creating tree 
  -e --ignore_extensions ext1,ext2  Ignore extensions while creating tree 

Listing files in a directory

Command: fmanager -p samples

By default, it will list files in the given directory (here samples). Output will look like this:

Got path: samples
sample.cpp
README.md
libcpp-file-manager.a
CMakeLists.txt
FileManager.hpp

Building tree of the given directory and ignoring directories and extensions

./fmanager -p ./ -t -d include,.git -e .cpp
OR
./fmanager --path ./ --tree --ignore_dirs include,.git --ignore_extensions .cpp

Got path: ./
tree.txt
CMakeLists.txt
samples
src
.github
README.md
.git
include

The tree.txt file stores the following directory structure:

|-- tree.txt
|-- CMakeLists.txt
|-- samples
    |-- libcpp-file-manager.a
    |-- CMakeLists.txt
    |-- README.md
    |-- FileManager.hpp
|-- src
|-- .github
    |-- workflows
        |-- build-filemanager.yml
|-- README.md
|-- .git
|-- include

Using the library in your C++ Code

To be able to use FileManager library, head over to the latest release and download .a (library file) and .hpp (header file). Copy these files in your current folder (or wherever you desire, just remember the path). To compile, use:

g++ filename.cpp -L . -lcpp-file-manager -o out

Here are a few steps on using the library in your code:

  1. Create an object of Filemanager Class and initialize it with a path:
FileManager file(path);
  1. The file.list_files() fucntion returns a vector containing names of files/directories with additional information. We can iterate through it as follows:
for (auto const& item: file.list_files()) {
    // Use item.rname if you want "just" the name of the file or folder
    // item.name returns absolute path (with respect to the path given)
    // item.is_dir returns true if it's a directory, else false
    std::cout << item.name << "\n";
}

The output will be as follows:

./tree.txt
./CMakeLists.txt
./samples
./src
./.github
./README.md
./.git
./include
  1. The file.writeToFile() call, creates a text file tree.txt representing the directory structure:
std::vector<std::string> ignore_dirs = {".git", ".github", ".vscode", "build"};
std::vector<std::string> ignore_extensions = {".pyc", ".swp"};
file.writeToFile(/*ignore_folders=*/ ignore_dirs, /*ignore_extensions=*/ ignore_extensions);

cpp-file-manager's People

Contributors

krshrimali avatar himanshusinghgh avatar imsrbh avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.