#include "stdafx.h" #include "Filesystem.h" #include #include bool FileOrDirectoryExists(const char* path) { DWORD attribs = GetFileAttributesA(path); return (attribs != INVALID_FILE_ATTRIBUTES); } bool FileExists(const char* path) { DWORD attribs = GetFileAttributesA(path); return (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY)); } bool DirectoryExists(const char* path) { DWORD attribs = GetFileAttributesA(path); return (attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY)); } bool GetFirstFileInDirectory(const char* directory, char* outFilePath, size_t outFilePathSize) { char searchPath[MAX_PATH]; printf(searchPath, MAX_PATH, "%s\\*", directory); WIN32_FIND_DATAA findData; HANDLE hFind = FindFirstFileA(searchPath, &findData); if (hFind == INVALID_HANDLE_VALUE) { return false; } do { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { // Found a file, copy its path to the output buffer printf(outFilePath, outFilePathSize, "%s\\%s", directory, findData.cFileName); FindClose(hFind); return true; } } while (FindNextFileA(hFind, &findData) != 0); FindClose(hFind); return false; // No files found in the directory } //str1k3r - credits to the smartCMD repo for this file