Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vertiginous/803576 to your computer and use it in GitHub Desktop.
Save vertiginous/803576 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <stdio.h>
int run(CHAR *path)
{
WIN32_FILE_ATTRIBUTE_DATA wfad;
int a, e;
printf("Checking '%s'\n", path);
a = GetFileAttributesEx(path, GetFileExInfoStandard, &wfad);
printf("Result: %d\n", a);
if (a) {
printf("wfad.dwFileAttributes: %d\n", wfad.dwFileAttributes);
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) printf("FILE_ATTRIBUTE_ARCHIVE\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) printf("FILE_ATTRIBUTE_COMPRESSED\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) printf("FILE_ATTRIBUTE_DEVICE\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) printf("FILE_ATTRIBUTE_DIRECTORY\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) printf("FILE_ATTRIBUTE_ENCRYPTED\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) printf("FILE_ATTRIBUTE_HIDDEN\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) printf("FILE_ATTRIBUTE_NORMAL\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) printf("FILE_ATTRIBUTE_NOT_CONTENT_INDEXED\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) printf("FILE_ATTRIBUTE_OFFLINE\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_READONLY) printf("FILE_ATTRIBUTE_READONLY\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) printf("FILE_ATTRIBUTE_REPARSE_POINT\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) printf("FILE_ATTRIBUTE_SPARSE_FILE\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) printf("FILE_ATTRIBUTE_SYSTEM\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) printf("FILE_ATTRIBUTE_TEMPORARY\n");
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_VIRTUAL) printf("FILE_ATTRIBUTE_VIRTUAL\n");
return -1;
} else {
e = GetLastError();
if ((e == ERROR_FILE_NOT_FOUND) || (e == ERROR_INVALID_NAME) ||
(e == ERROR_PATH_NOT_FOUND)) {
printf("GetLastError: %d\n", e);
}
return 0;
}
}
void find(CHAR *path)
{
HANDLE h;
WIN32_FIND_DATA fd;
int e;
printf("FindFirstFile '%s'\n", path);
h = FindFirstFile(path, &fd);
if (h != INVALID_HANDLE_VALUE) {
FindClose(h);
printf("fd.cFileName: '%s'\n", fd.cFileName);
} else {
e = GetLastError();
printf("GetLastError: %d\n", e);
}
}
void main()
{
CHAR *path;
path = "C:/Users/gthiesfeld/Work/repo/rubyinstaller/sandbox";
if (!(run(path))) {
find(path);
}
printf("=================\n");
path = "C:/Users/gthiesfeld/Work/repo/rubyinstaller/sandbox/...";
run(path);
find(path);
printf("=================\n");
path = "C:/Users/gthiesfeld/Work/repo/rubyinstaller/sandbox/ruby19_mingw/bin/ruby.exe.";
run(path);
find(path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment