Login Languish
Functions
file_utils.cpp File Reference

handles file related tasks More...

#include "file_utils.h"
#include "random_utils.h"
#include "compatibility_utils.h"
#include "utils.h"
#include <iostream>
#include <sstream>
#include <map>
Include dependency graph for file_utils.cpp:

Functions

std::vector< fs::path > file_utils::listSubdirectories (fs::path path)
 lists subdirectories in a directory More...
 
std::vector< fs::path > file_utils::listFiles (fs::path path)
 lists files in a directory More...
 
std::vector< fs::path > file_utils::getNRandomFiles (size_t n, fs::path directory)
 retrieves n random files More...
 
fs::path file_utils::getRandomFile (fs::path directory)
 retrieves a random file More...
 
std::vector< fs::path > file_utils::getNRandomFilesFromSubdirectories (size_t n, const std::vector< fs::path > &directories)
 retrieves n random files from given subdirectories More...
 
fs::path file_utils::getPathToResource (const std::string &resource)
 retrieves the resource path More...
 
std::vector< std::string > file_utils::convertPathsToFrontendStrings (const std::vector< fs::path > &paths)
 converts file paths to frontend strings More...
 
std::string file_utils::convertPathToFrontendString (fs::path path)
 converts file path to frontend string More...
 
std::vector< std::vector< std::string > > file_utils::readCSV (fs::path path)
 

Detailed Description

handles file related tasks

Author
Cameron Bruce

Function Documentation

◆ convertPathsToFrontendStrings()

std::vector< std::string > file_utils::convertPathsToFrontendStrings ( const std::vector< fs::path > &  paths)

converts file paths to frontend strings

passes file paths in a given vector to a helper function to convert into strings for the frontend

Parameters
pathsvector of file paths
Returns
vector of frontend strings

◆ convertPathToFrontendString()

std::string file_utils::convertPathToFrontendString ( fs::path  path)

converts file path to frontend string

converts the file path to a string relative to the frontend and url encodes it

Parameters
patha file path
Returns
a frontend string

◆ getNRandomFiles()

std::vector< fs::path > file_utils::getNRandomFiles ( size_t  n,
fs::path  directory 
)

retrieves n random files

creates and returns a filepath vector of n random files in the directory

Parameters
nnumber of random files to return
directorypath of the directory to retrieve files from
Returns
vector of n random file paths

◆ getNRandomFilesFromSubdirectories()

std::vector< fs::path > file_utils::getNRandomFilesFromSubdirectories ( size_t  n,
const std::vector< fs::path > &  directories 
)

retrieves n random files from given subdirectories

creates and returns a file path vector of n random files from the subdirectories

Parameters
nnumber of random files to return
subdirectoriesvector of subdirectories to retrieve random files from
Returns
vector of n random file paths

◆ getPathToResource()

fs::path file_utils::getPathToResource ( const std::string &  resource)

retrieves the resource path

Parameters
resourcestring representation of resource
Returns
the resource path

◆ getRandomFile()

fs::path file_utils::getRandomFile ( fs::path  directory)

retrieves a random file

returns the filepath of a random file in the directory

Parameters
pathpath of the directory to retrieve the file from
Returns
a random file's path

◆ listFiles()

std::vector< fs::path > file_utils::listFiles ( fs::path  path)

lists files in a directory

creates and returns a filepath vector of the files in directory

Parameters
pathpath of the directory to list files from
Returns
vector of file paths

◆ listSubdirectories()

std::vector< fs::path > file_utils::listSubdirectories ( fs::path  path)

lists subdirectories in a directory

creates and returns a filepath vector of the subdirectories in the directory

Parameters
pathpath of the directory to list subdirectories from
Returns