In my application, there is a part where I need to list the sub-directories and files in a given path. It works fine (or so it seems :) ) for local paths, but acts weird when user enters network shared paths.
If I give network shared path \\host_name\shared_dir\*
, my application can list all the subdirectories and files under \\host_name\shared_dir\
but If user gives just \\host_name\*
, then FindFirstFile fails. !!! < But user can access \\host_name\
path in windows explorer, so there is no permission issue as such!!! >
Here is a code snippet showing the way I am using FindFirstFile
#include <stdio.h>
#include <Windows.h>
int main()
{
char l_host_name[开发者_开发技巧64] = "\\\\host_name\\*";
WIN32_FIND_DATA search_data = { 0 };
HANDLE search_handle;
BOOL next_ret_val = 1;
search_handle = FindFirstFile(l_host_name, &search_data);
if(INVALID_HANDLE_VALUE != search_handle)
{
printf("Name = %s\n", search_data.cFileName);
do
{
next_ret_val = FindNextFile(search_handle, &search_data);
printf("Name = %s\n", search_data.cFileName);
} while(next_ret_val != 0);
FindClose(search_handle);
}
else
{
printf("failed to get search handle\n");
}
return 0;
}
精彩评论