| LogDoctor 4.00 Parse Apache2/Nginx/IIS logs and view dinamically generated statistics

Loading...
Searching...
No Matches
Functions
IOutils Namespace Reference

IOUtils. More...

## Functions
bool | checkFile (std::string_view path, const bool readable=false, const bool writable=false) noexcept
| Checks if a path exists, if it points to a file and if the user has read and/or write permissions on it.
bool | checkDir (std::string_view path, const bool readable=false, const bool writable=false) noexcept
| Checks if a path exists, if it points to a folder and if the user has read and/or write permissions on it.
bool | makeDir (std::string_view path, std::error_code &err) noexcept
| Creates a directory.
bool | renameAsCopy (std::string_view path, std::error_code &err) noexcept
| Renames an entry with a trailing '.copy'.
void | readFile (const std::string &path, std::string &content)
| Reads the content of a file.
void | randomLines (const std::string &path, std::vector< std::string > &lines, const size_t n_lines=16ul, const bool strip_lines=true)
| Randomly pick lines from a file.
void | writeOnFile (const std::string &path, std::string_view content)
| Writes a string on file.
bool | exists (std::string_view path) noexcept
| Checks the existence of a file/folder.
bool | isFile (std::string_view path) noexcept
| Checks if a path exists and points to a file.
bool | isDir (std::string_view path) noexcept
| Checks if a path exists and points to a directory.

## Detailed Description

IOUtils.

Utilities to work on files

## Function Documentation

## ◆ checkDir()

bool IOutils::checkDir | ( | std::string_view | path,
|  | const bool | readable = false,
|  | const bool | writable = false )
| noexcept

Checks if a path exists, if it points to a folder and if the user has read and/or write permissions on it.

Parameters

  path | The path of the entry
  readable | Set to true to check for readability
  writable | Set to true to check for writability

Returns
  The result of the checks

## ◆ checkFile()

bool IOutils::checkFile | ( | std::string_view | path,
|  | const bool | readable = false,
|  | const bool | writable = false )
| noexcept

Checks if a path exists, if it points to a file and if the user has read and/or write permissions on it.

Parameters

  path | The path of the entry
  readable | Set to true to check for readability
  writable | Set to true to check for writability

Returns
  The result of the checks

## ◆ exists()

bool IOutils::exists | ( | std::string_view | path | ) |
| inline noexcept

Checks the existence of a file/folder.

Parameters

  path | The path of the entry

Returns
  The result of the check

## ◆ isDir()

bool IOutils::isDir | ( | std::string_view | path | ) |
| inline noexcept

Checks if a path exists and points to a directory.

Parameters

  path | The path of the entry

Returns
  The result of the checks

## ◆ isFile()

bool IOutils::isFile | ( | std::string_view | path | ) |
| inline noexcept

Checks if a path exists and points to a file.

Parameters

  path | The path of the entry

Returns
  The result of the check

## ◆ makeDir()

bool IOutils::makeDir | ( | std::string_view | path,
|  | std::error_code & | err )
| noexcept

Creates a directory.

Parameters

  path | The path of the new entry

Returns
  Wheter the operation was successful or not

## ◆ randomLines()

void IOutils::randomLines | ( | const std::string & | path,
|  | std::vector< std::string > & | lines,
|  | const size_t | n_lines = 16ul,
|  | const bool | strip_lines = true )

Randomly pick lines from a file.

Parameters

  path | The path of the entry
  lines | Will hold the picked lines
  n_lines | The number of lines to pick
  strip_lines | Whether to strip control-characters away from the lines

## ◆ readFile()

void IOutils::readFile | ( | const std::string & | path,
|  | std::string & | content )

Reads the content of a file.

Parameters

  path | The path of the file to read from
  content | Will hold the content of the file

## ◆ renameAsCopy()

bool IOutils::renameAsCopy | ( | std::string_view | path,
|  | std::error_code & | err )
| noexcept

Renames an entry with a trailing '.copy'.

Parameters

  path | The path of the entry to rename
  err | Will hold the error, if any

Returns
  Wheter the operation was successful or not

## ◆ writeOnFile()

void IOutils::writeOnFile | ( | const std::string & | path,
|  | std::string_view | content )

Writes a string on file.

Parameters

  path | The path of the file to write on
  content | The string to write