how to access a shared folder in another machine using C language

3.5k Views Asked by At

I'm new in C/C++ and I need to retrieve images from a shared folder place in another computer for processing. How can I do that? Can someone please provide me some guidance or sample codes on how to do it? Besides, can I also get the list of files in a folder in the shared folder?

2

There are 2 best solutions below

0
On BEST ANSWER

Open a file for reading:

char* filename = "//machine/shared/image.jpg";
FILE* f = fopen(filename, "r");

Read a directory:

struct dirent* ent;
char* path = "//machine/shared";

DIR* d = opendir(path);
while((ent = readdir(d)) != NULL)
{
    printf("%s\n", ent->d_name);
}
1
On

Assuming you are on Windows, you can use a UNC path to refer to the file and use normal C/C++ IO (fopen or fstream). Just be sure to escape it correctly as part of the C string.