/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #pragma once #include #include #include #include #include namespace FileUtils { std::string GetCurrentFolder(); bool FileExists(const std::string& folderPath); bool FolderExists(const std::string& folderPath); std::vector ListFolderFiles( const std::string folder, const std::set& matchExtensions); bool CreatePath(std::string path); bool CopyFile( const std::string& srcFilename, const std::string& dstFilename, bool createPath = false); inline std::string GetAbsolutePath(const std::string& filePath) { return boost::filesystem::absolute(filePath).string(); } inline std::string GetCurrentFolder() { return boost::filesystem::current_path().string(); } inline bool FileExists(const std::string& filePath) { return boost::filesystem::exists(filePath) && boost::filesystem::is_regular_file(filePath); } inline bool FolderExists(const std::string& folderPath) { return boost::filesystem::exists(folderPath) && boost::filesystem::is_directory(folderPath); } inline std::string getFolder(const std::string& path) { return boost::filesystem::path(path).parent_path().string(); } inline std::string GetFileName(const std::string& path) { return boost::filesystem::path(path).filename().string(); } inline std::string GetFileBase(const std::string& path) { return boost::filesystem::path(path).stem().string(); } inline boost::optional GetFileSuffix(const std::string& path) { const auto& extension = boost::filesystem::path(path).extension(); if (extension.empty()) { return boost::none; } return extension.string().substr(1); } } // namespace FileUtils