files.cpp 1.01 KB
Newer Older
Matteo's avatar
update  
Matteo committed
1
2
#include "files.h"

Matteo's avatar
Matteo committed
3
4
#include <iostream>

Matteo's avatar
update  
Matteo committed
5
6
using std::cout, std::endl, std::cerr, std::ofstream, std::ios;

Matteo's avatar
Matteo committed
7
void files::save_file(std::filesystem::path fileName, std::string content) {
Matteo's avatar
Matteo committed
8
    ofstream outputFile;
Matteo's avatar
Matteo committed
9
    outputFile.open(fileName);
Matteo's avatar
Matteo committed
10
11
    outputFile << content << endl;
    outputFile.close();
Matteo's avatar
update  
Matteo committed
12
13
14
}

void files::findFileNameFromPath(std::string* path, std::string* fileName, std::string* extension) {
Matteo's avatar
Matteo committed
15
16
17
18
19
    *path = path->substr(path->find_last_of("'") + 1, path->size());
    std::string path_without_extension = path->substr(0, path->find_last_of("."));
    *fileName =
        path_without_extension.substr(path_without_extension.find_last_of("/") + 1, path_without_extension.size());
    *extension = path->substr(path->find_last_of(".") + 1, path->size());
Matteo's avatar
update  
Matteo committed
20
21
}

Matteo's avatar
Matteo committed
22
23
std::pair<std::string, std::string> files::get_filename_and_extension(std::string videoPath) {
    std::string fileName, extension;
Matteo's avatar
update  
Matteo committed
24
25
    files::findFileNameFromPath(&videoPath, &fileName, &extension);

Matteo's avatar
Matteo committed
26
    return std::pair<std::string, std::string>(fileName, extension);
Matteo's avatar
update  
Matteo committed
27
}