[IO] Use C++17 filesystem features for directory interaction

This commit is contained in:
momo5502 2016-11-19 20:39:39 +01:00
parent 964db896d6
commit b7b7292bd4
3 changed files with 12 additions and 34 deletions

View File

@ -39,6 +39,9 @@
#include <future> #include <future>
#include <queue> #include <queue>
// Experimental C++17 features
#include <filesystem>
#ifdef ENABLE_DXSDK #ifdef ENABLE_DXSDK
#include <D3dx9tex.h> #include <D3dx9tex.h>
#pragma comment(lib, "D3dx9.lib") #pragma comment(lib, "D3dx9.lib")

View File

@ -56,45 +56,19 @@ namespace Utils
bool CreateDirectory(std::string dir) bool CreateDirectory(std::string dir)
{ {
char opath[MAX_PATH] = { 0 }; return std::experimental::filesystem::create_directories(dir);
char *p; }
size_t len;
strncpy_s(opath, dir.data(), sizeof(opath)); std::vector<std::string> ListFiles(std::string dir)
len = strlen(opath); {
std::vector<std::string> files;
if (opath[len - 1] == L'/') for (auto& file : std::experimental::filesystem::directory_iterator(dir))
{ {
opath[len - 1] = L'\0'; files.push_back(file.path().generic_string());
} }
for (p = opath; *p; p++) return files;
{
if (*p == L'/' || *p == L'\\')
{
*p = L'\0';
if (_access(opath, 0))
{
if (_mkdir(opath) == -1)
{
return false;
}
}
*p = L'\\';
}
}
if (_access(opath, 0))
{
if (_mkdir(opath) == -1)
{
return false;
}
}
return true;
} }
} }
} }

View File

@ -6,5 +6,6 @@ namespace Utils
void WriteFile(std::string file, std::string data); void WriteFile(std::string file, std::string data);
std::string ReadFile(std::string file); std::string ReadFile(std::string file);
bool CreateDirectory(std::string dir); bool CreateDirectory(std::string dir);
std::vector<std::string> ListFiles(std::string dir);
} }
} }