SCLS Foundation File

Presentation

SCLS Foundamental File contains some basics but usefull functions to do some simple file editing with C++. It's not the most filled SCLS Foundamental. Indeed, the C++ std library filesystem added in C++ 17 adds a lot of very usefull functions with files. This file adds some others simples functions, by using filesystem.

Get datas about files

SCLS Foundamental File adds some functions made to describe a file / directory. In fact, this functions are just some simplification of the filesystem functions, which are usefull in some cases. You can analyse easily a directory. The function "directory_content" allows a simple access to the sub-files of a directory. You can also have some basics informations about a file with "file_extension" which gives the extension and "file_name" which gives the name of the file.

Functions

std::vector<std::string> directory_content(std::string path, bool sub_directory = false)

Return each sub-files's path of the directory "path" in a std::vector of std::string. If "sub_directory" is true, adds the sub-files of the sub-directories in "path". If any kinds of error occurs, the returned std::vector is empty.

std::string file_extension(std::string path, bool with_point = false)

Return the extension of "path", with the point at the start if "with_point" is true.

std::string file_name(std::string path, bool with_extension = false)

Return the name of "path", with the extension if "with_extension" is true.

Read and write in files

SCLS Foundamental File allows the user to read or write in a file, very very easily. It allows to do that in only one line of code.

Functions

std::string read_file(std::string path)

Reads the entire file "path", and returns it. If any kinds of error occurs, "" is returned.
This function was added in the version 0.1 and last edited in the version 0.1.

void write_in_file(std::string path, std::string to_write, std::ios::openmode opening_mode = std::ios::out)

Erases or creates "path", then writes "to_write" in it. You can handle the mode of opening with "opening_mode".
This function was added in the version 0.1 and last edited in the version 0.1.

Code specification

This file define the macro "SCLS_FOUNDATION_FILE".