So far I have this which I found here on Stack Overflow, but this only displays a file from the path given in the program, not provided by the user.
I've tried to add variables to the printfile
function but with no effect.
int findfile_recursive(const char *folder, const char *filename, char *fullpath )
{
char wildcard[MAX_PATH];
sprintf(wildcard, "%s\\*", folder);
WIN32_FIND_DATA fd;
HANDLE handle = FindFirstFile(wildcard, &fd);
if(handle == INVALID_HANDLE_VALUE) return 0;
do
{
if(strcmp(fd.cFileName, ".") == 0 || strcmp(fd.cFileName, "..") == 0)
continue;
char path[MAX_PATH];
sprintf(path, "%s\\%s", folder, fd.cFileName);
if(_stricmp(fd.cFileName, filename) == 0)
strcpy(fullpath, path);
else if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
findfile_recursive(path, filename, fullpath);
if(strlen(fullpath))
break;
} while(FindNextFile(handle, &fd));
FindClose(handle);
return strlen(fullpath);
}
int printfile(void)
{
char a,b;
printf("Path: ");
gets(a);
printf("Name: ");
gets(b);
char fullpath[MAX_PATH] = { 0 };
if(findfile_recursive(&a, &b, fullpath)){
printf("found: %s\n", fullpath);
}
else{
printf("Nothing found");
}
}