2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-10-21 18:58:50 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/directory.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdio>
|
|
|
|
#include <dirent.h>
|
2022-10-21 18:58:50 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-10-21 18:58:50 +08:00
|
|
|
namespace NEO::Directory {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-10-21 18:58:50 +08:00
|
|
|
std::vector<std::string> getFiles(const std::string &path) {
|
2017-12-21 07:45:38 +08:00
|
|
|
std::vector<std::string> files;
|
|
|
|
|
|
|
|
DIR *dir = opendir(path.c_str());
|
|
|
|
if (dir == nullptr) {
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dirent *entry = nullptr;
|
|
|
|
while ((entry = readdir(dir)) != nullptr) {
|
|
|
|
if (entry->d_name[0] == '.') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string fullPath;
|
|
|
|
fullPath += path;
|
|
|
|
fullPath += "/";
|
|
|
|
fullPath += entry->d_name;
|
|
|
|
|
|
|
|
files.push_back(fullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
return files;
|
|
|
|
}
|
2022-10-21 18:58:50 +08:00
|
|
|
|
|
|
|
void createDirectory(const std::string &path) {
|
|
|
|
const mode_t mode = 0777; // 777 in base 8
|
|
|
|
mkdir(path.c_str(), mode);
|
|
|
|
}
|
|
|
|
}; // namespace NEO::Directory
|