File size: 4,211 Bytes
7fc5a59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef OPENPOSE_UTILITIES_FILE_SYSTEM_HPP
#define OPENPOSE_UTILITIES_FILE_SYSTEM_HPP

#include <openpose/core/common.hpp>

namespace op
{
    OP_API void makeDirectory(const std::string& directoryPath);

    OP_API bool existDirectory(const std::string& directoryPath);

    OP_API bool existFile(const std::string& filePath);

    /**
     * This function makes sure that the directoryPathString is properly formatted. I.e., it
     * changes all '\' by '/', and it makes sure that the string finishes with '/'.
     * @param directoryPathString std::string with the directory path to be formatted.
     * @return std::string with the formatted directory path.
     */
    OP_API std::string formatAsDirectory(const std::string& directoryPathString);

    /**
     * This function extracts the file name and extension from a full path.
     * @param fullPath std::string with the full path.
     * @return std::string with the file name with extension.
     */
    OP_API std::string getFileNameAndExtension(const std::string& fullPath);

    /**
     * This function extracts the file name (without extension) from a full path.
     * @param fullPath std::string with the full path.
     * @return std::string with the file name without extension.
     */
    OP_API std::string getFileNameNoExtension(const std::string& fullPath);

    /**
     * This function extracts the extension from a full path.
     * E.g., if fullPath is `/media/document.txt`, output will be `txt`
     * @param fullPath std::string with the full path.
     * @return std::string with the file extension.
     */
    OP_API std::string getFileExtension(const std::string& fullPath);

    /**
     * This function extracts the full file path without its extension from a full file path.
     * @param fullPath std::string with the full path.
     * @return std::string with the full file path without extension.
     */
    OP_API std::string getFullFilePathNoExtension(const std::string& fullPath);

    /**
     * This function extracts the full file path of the folder where it is contained.
     * @param fullPath std::string with the full path.
     * @return std::string with the full file path of the folder.
     */
    OP_API std::string getFileParentFolderPath(const std::string& fullPath);

    /**
     * This function extracts all the files in a directory path with the desired
     * extensions. If no extensions is specified, then all the file names are returned.
     * @param directoryPath std::string with the directory path.
     * @param extensions std::vector<std::string> with the extensions of the desired files.
     * @return std::vector<std::string> with the existing file names.
     */
    OP_API std::vector<std::string> getFilesOnDirectory(
        const std::string& directoryPath, const std::vector<std::string>& extensions = {});

    /**
     * Analogous to getFilesOnDirectory(const std::string& directoryPath, const std::vector<std::string>& extensions)
     * for 1 specific extension.
     * @param directoryPath std::string with the directory path.
     * @param extension std::string with the extension of the desired files.
     * @return std::vector<std::string> with the existing file names.
     */
    OP_API std::vector<std::string> getFilesOnDirectory(
        const std::string& directoryPath, const std::string& extension);

    /**
     * This function extracts all the files in a directory path with the desired
     * group of extensions (e.g., Extensions::Images).
     * @param directoryPath std::string with the directory path.
     * @param extensions Extensions with the kind of extensions desired (e.g., Extensions:Images).
     * @return std::vector<std::string> with the existing file names.
     */
    OP_API std::vector<std::string> getFilesOnDirectory(
        const std::string& directoryPath, const Extensions extensions);

    OP_API std::string removeSpecialsCharacters(const std::string& stringToVariate);

    OP_API void removeAllOcurrencesOfSubString(std::string& stringToModify, const std::string& substring);

    OP_API void replaceAll(std::string& stringText, const char charToChange, const char charToAdd);
}

#endif // OPENPOSE_UTILITIES_FILE_SYSTEM_HPP