filesystem判断文件或文件夹是否存在

class CFileSystem {
public:
	CFileSystem(CFileSystem&) = delete;
	CFileSystem(CFileSystem&&) = delete;
	CFileSystem(){}
	/// 
	/// 判断文件或文件夹是否存在
	/// 
	/// 路径
	/// true:判断是否是文件夹,false:判断是否是文件
	/// 路径的文件或文件夹是否存在
	bool IsExist(const std::filesystem::path& path, bool is_directory)const {

		std::error_code error;
		auto file_status = std::filesystem::status(path, error);
		if (error) {
			return false;
		}

		if (!std::filesystem::exists(file_status)) {
			return false;
		}
		return  std::filesystem::is_directory(file_status) && is_directory;
	}
	bool IsFileExist(const std::filesystem::path& path)const {
		return IsExist(path, false);
	}
	bool IsFileExist(const std::string_view& path)const {
		return IsFileExist(std::filesystem::path(path));
	}
	bool IsFileExist(const std::wstring_view& path)const {
		return IsFileExist(std::filesystem::path(path));
	}
	bool IsFileExist(const wchar_t* path)const {
		return IsFileExist(std::wstring_view(path));
	}
	bool IsFileExist(const char* path)const {
		return IsFileExist(std::string_view(path));
	}
	bool IsDirExist(const std::filesystem::path& path)const {
		return IsExist(path, true);
	}
	bool IsDirExist(const std::string_view& path)const {
		return IsDirExist(std::filesystem::path(path));
	}
	bool IsDirExist(const std::wstring_view& path)const {
		return IsDirExist(std::filesystem::path(path));
	}
	bool IsDirExist(const wchar_t* path)const {
		return IsDirExist(std::wstring_view(path));
	}
	bool IsDirExist(const char* path)const {
		return IsDirExist(std::string_view(path));
	}
	
	std::filesystem::path::string_type GetCurrentPath()const
	{
		using std::filesystem::current_path;
		return current_path().native();
	}
	void Emun(const std::filesystem::path& path,bool EnumChild,std::function callback)const
	{
		using std::filesystem::directory_iterator;
		for (auto& p : directory_iterator(path)) {
			if (!callback(p.path()))
				break;
			if (EnumChild && IsExist(p.path(),true))
			{
				Emun(p.path(), EnumChild, callback);
			}
		}
	}
};

bool PrintDir(const std::filesystem::path& path)
{
	std::cout << path<

 

你可能感兴趣的:(C++17)