namespace ngraph::file_util

Overview

namespace file_util {

// global functions

NGRAPH_API std::string get_file_name(const std::string& path);
NGRAPH_API std::string get_file_ext(const std::string& path);
NGRAPH_API std::string get_directory(const std::string& path);
NGRAPH_API std::string path_join(const std::string& s1, const std::string& s2);

NGRAPH_API std::string path_join(
    const std::string& s1,
    const std::string& s2,
    const std::string& s3
    );

NGRAPH_API std::string path_join(
    const std::string& s1,
    const std::string& s2,
    const std::string& s3,
    const std::string& s4
    );

NGRAPH_API void iterate_files(
    const std::string& path,
    std::function<void(const std::string&file, bool is_dir)> func,
    bool recurse = false,
    bool include_links = false
    );

NGRAPH_API void convert_path_win_style(std::string& path);
NGRAPH_API std::string wstring_to_string(const std::wstring& wstr);
NGRAPH_API std::wstring multi_byte_char_to_wstring(const char* str);
NGRAPH_API std::string sanitize_path(const std::string& path);

} // namespace file_util

Detailed Documentation

Global Functions

NGRAPH_API std::string get_file_name(const std::string& path)

Returns the name with extension for a given path.

Parameters:

path

The path to the output file

NGRAPH_API std::string get_file_ext(const std::string& path)

Returns the file extension.

Parameters:

path

The path to the output file

NGRAPH_API std::string get_directory(const std::string& path)

Returns the directory portion of the given path.

Parameters:

path

The path to the output file

NGRAPH_API std::string path_join(const std::string& s1, const std::string& s2)

Joins multiple paths into a single path.

Parameters:

s1

Left side of path

s2

Right side of path

NGRAPH_API void iterate_files(
    const std::string& path,
    std::function<void(const std::string&file, bool is_dir)> func,
    bool recurse = false,
    bool include_links = false
    )

Iterate through files and optionally directories. Symbolic links are skipped.

Parameters:

path

The path to iterate over

func

A callback function called with each file or directory encountered

recurse

Optional parameter to enable recursing through path

NGRAPH_API void convert_path_win_style(std::string& path)

Change Linux-style path (‘/’) to Windows-style (‘’)

Parameters:

path

The path to change file separator

NGRAPH_API std::string wstring_to_string(const std::wstring& wstr)

Conversion from wide character string to a single-byte chain.

Parameters:

wstr

A wide-char string

Returns:

A multi-byte string

NGRAPH_API std::wstring multi_byte_char_to_wstring(const char* str)

Conversion from single-byte chain to wide character string.

Parameters:

str

A null-terminated string

Returns:

A wide-char string

NGRAPH_API std::string sanitize_path(const std::string& path)

Remove path components which would allow traversing up a directory tree.

Parameters:

path

A path to file

Returns:

A sanitiazed path