From a211fe1bbcb8e160136f3dd22b516ba751d4b02e Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 15 Mar 2016 10:14:53 +0100 Subject: ICE-7019 - remove db tools dependency on IcePatch2 --- cpp/src/IceUtil/FileUtil.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'cpp/src/IceUtil/FileUtil.cpp') diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp index ea7fc606e65..dfcbf670b5c 100644 --- a/cpp/src/IceUtil/FileUtil.cpp +++ b/cpp/src/IceUtil/FileUtil.cpp @@ -17,8 +17,12 @@ #ifdef _WIN32 # include # include +# ifndef ICE_OS_WINRT +# include +# endif #else # include +# include #endif using namespace std; @@ -89,6 +93,41 @@ IceUtilInternal::directoryExists(const string& path) return true; } +// +// Determinte if a directory exists and is empty +// +#ifndef ICE_OS_WINRT +bool +IceUtilInternal::isEmptyDirectory(const string& path) +{ +# ifdef _WIN32 + return PathIsDirectoryEmptyW(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str()); +# else + struct dirent* d; + DIR* dir = opendir(path.c_str()); + if(dir) + { + bool empty = true; + while((d = readdir(dir))) + { + string name(d->d_name); + if(name != "." && name != "..") + { + empty = false; + break; + } + } + closedir(dir); + return empty; + } + else + { + return false; + } +# endif +} +#endif + // // Determine if a regular file exists. // -- cgit v1.2.3