Exemplo n.º 1
0
bool getFileInfo(const char *path, FileInfo *fileInfo)
{
	// TODO: Expand relative paths?
	fileInfo->fullName = path;

#ifdef _WIN32
	DWORD attributes = GetFileAttributes(path);
	fileInfo->isDirectory = (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
	fileInfo->isWritable = (attributes & FILE_ATTRIBUTE_READONLY) == 0;
#else
	struct stat64 file_info;

	std::string copy(path);
	stripTailDirSlashes(copy);

	int result = stat64(copy.c_str(), &file_info);

	if (result < 0) {
		WLOG("IsDirectory: stat failed on %s", path);
		return false;
	}

	fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
	fileInfo->isWritable = false;
	// HACK: approximation
	if (file_info.st_mode & 0200)
		fileInfo->isWritable = true;
#endif
	return true;
}
Exemplo n.º 2
0
bool getFileInfo(const char *path, FileInfo *fileInfo)
{
	// TODO: Expand relative paths?
	fileInfo->fullName = path;

#ifdef _WIN32
	fileInfo->size = 0;
	WIN32_FILE_ATTRIBUTE_DATA attrs;
	if (GetFileAttributesExA(path, GetFileExInfoStandard, &attrs)) {
		fileInfo->size = (uint64_t)attrs.nFileSizeLow | ((uint64_t)attrs.nFileSizeHigh << 32);
	}
	fileInfo->isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
	fileInfo->isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
#else
	struct stat64 file_info;

	std::string copy(path);
	stripTailDirSlashes(copy);

	int result = stat64(copy.c_str(), &file_info);

	if (result < 0) {
		WLOG("IsDirectory: stat failed on %s", path);
		return false;
	}

	fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
	fileInfo->isWritable = false;
	fileInfo->size = file_info.st_size;
	// HACK: approximation
	if (file_info.st_mode & 0200)
		fileInfo->isWritable = true;
#endif
	return true;
}
Exemplo n.º 3
0
// Returns true if file filename exists
bool exists(const std::string &filename) {
#ifdef _WIN32
    std::wstring wstr = ConvertUTF8ToWString(filename);
    return GetFileAttributes(wstr.c_str()) != 0xFFFFFFFF;
#else
    struct stat64 file_info;

    std::string copy(filename);
    stripTailDirSlashes(copy);

    int result = stat64(copy.c_str(), &file_info);

    return (result == 0);
#endif
}