Skip to content

πŸ“ β€’ fileManager is a C++ library designed to provide a friendlier approach to managing persistent data.

Notifications You must be signed in to change notification settings

bracesoftware/fileManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

File Manager

πŸ“ β€’ File Manager is a C++ library designed to provide a friendlier approach to managing persistent data.

How to use?

int main(int argc, char *argv[])
{
    flmgr::main(argc,argv);
    return 0;
}

<>.set_name(std::string newname)

  • File type required: all directories and files
  • Rename an object.
myFile.set_name("something.txt");

<>.get_name()

  • File type required: all directories and files
  • Get object name.
std::string filename = myFile.get_name();

<>.remove()

  • File type required: all directories and files
  • Remove the directory or file.
myFile.remove();

<>.exists()

  • File type required: all directories and files
  • Check if a file or directory exists.
if(myFile.exists()){
    //foo
}

Declaring directories as objects

flmgr::dir myDir("myDir");

Functions

<>.create()

  • File type required: flmgr::filetype::txt
  • Remove all contents from a file, and then write text to it.
myDir.create();

Declaring files as objects

flmgr::file<flmgr::filetype::txt> myFile("randomfile.txt");
  • In order to create an object holding the name of a file in a directory, use the overloaded constructor:
flmgr::file<flmgr::filetype::txt> myFile(myDir, "randomfile.txt");
  • Here myDir is a directory object created using the flmgr::dir class.

Functions

<>.overwrite_text(std::string text)

  • File type required: flmgr::filetype::txt
  • Remove all contents from a file, and then write text to it.
myFile.overwrite_text("test");

<>.append_text(std::string text)

  • File type required: flmgr::filetype::txt
  • Append text to a file.
myFile.append_text("test");

<>.read_text(std::vector<std::string> &dest)

  • File type required: flmgr::filetype::txt
  • Read a file line by line and store each line in a vector.
std::vector<std::string>fileContents;
myFile.read_text(fileContents);

<>.read_line(int line, std::string &dest)

  • File type required: flmgr::filetype::txt
  • Read a specific line.
std::string line;
myFile.read_line(4,line);
std::cout << "line content is : '" << line << "'" << std::endl;

<>.remove_content()

  • File type required: all files
  • Remove all file contents.
myFile.remove_content();

<>.set_key(std::string key, std::string value)

  • File type required: flmgr::filetype::ini
  • Set a value in an INI file.
myFile.set_key("Key", "value");

<>.get_key(std::string key)

  • File type required: flmgr::filetype::ini
  • Get a value stored in an INI file.
std::string value = myFile.get_key("Key");

<>.get_keys(std::unordered_map<std::string, std::string> &dest)

  • File type required: flmgr::filetype::ini
  • Read all values stored in an INI file and store them in an unordered map.
std::unordered_map<std::string, std::string> mymap;
myFile.get_keys(mymap);

for(auto &i : mymap)
{
    std::cout << i.first << "=" << i.second << std::endl;
}

FAQ

Creating directories in directories?

flmgr::dir myPath("dir1/dir2");
  • Of course, declaring an object like that will obviously not work, so we need to do it like this:
flmgr::dir myPath; // leave the myPath "uninitialised" (it is initialised internally)

myPath.set_name("dir1");
myPath.create();

myPath.set_name("dir1/dir2");
myPath.create();

flmgr::file<flmgr::filetype::txt> FileInPath(myPath, "file.txt");

FileInPath.append_text("tesadasdast");

Extra features

Bit arrays

  • You can create bit arrays.
flmgr::extra::bitarray<8> myBitArray;

std::cout << "bitarray size: " << myBitArray.get_size() << std::endl;

myBitArray.set_at(3,1);
myBitArray.set_at(4,1);
myBitArray.set_at(7,1);
myBitArray.set_at(1,1);

for(int i = 0; i < myBitArray.get_size(); i++)
{
    std::cout << "bitarray<" << i << "> = " << myBitArray.get_at(i) << std::endl;
}

Output:

bitarray size: 8
bitarray<0> = 0
bitarray<1> = 1
bitarray<2> = 0
bitarray<3> = 1
bitarray<4> = 1
bitarray<5> = 0
bitarray<6> = 0
bitarray<7> = 1

About

πŸ“ β€’ fileManager is a C++ library designed to provide a friendlier approach to managing persistent data.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages