π β’ File Manager is a C++ library designed to provide a friendlier approach to managing persistent data.
int main(int argc, char *argv[])
{
flmgr::main(argc,argv);
return 0;
}- File type required:
all directories and files - Rename an object.
myFile.set_name("something.txt");- File type required:
all directories and files - Get object name.
std::string filename = myFile.get_name();- File type required:
all directories and files - Remove the directory or file.
myFile.remove();- File type required:
all directories and files - Check if a file or directory exists.
if(myFile.exists()){
//foo
}flmgr::dir myDir("myDir");- File type required:
flmgr::filetype::txt - Remove all contents from a file, and then write text to it.
myDir.create();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
myDiris a directory object created using theflmgr::dirclass.
- File type required:
flmgr::filetype::txt - Remove all contents from a file, and then write text to it.
myFile.overwrite_text("test");- File type required:
flmgr::filetype::txt - Append text to a file.
myFile.append_text("test");- 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);- 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;- File type required:
all files - Remove all file contents.
myFile.remove_content();- File type required:
flmgr::filetype::ini - Set a value in an INI file.
myFile.set_key("Key", "value");- File type required:
flmgr::filetype::ini - Get a value stored in an INI file.
std::string value = myFile.get_key("Key");- 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;
}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");- 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