|
SMB recursive directory scan March 26, 2009 04:30AM | Registered: 17 years ago Posts: 78 |
directory1/
sub_directory1/
file1
file2
file3
sub_directory2/
file4
file5
file6
directory2/
sub_directory3/
file7
sub_directory4/
file8
...scanning this on the sd:/ or usb:/ device will find all the files, but smb:/ will traverse into directory1, then sub_directory1, find file1, file2 and file3, then not find anything else.
void recurse(char *path) {
DIR *dir = opendir(path);
if (!dir) {
printf("failed to open directory \"%s\"\n", path);
return;
}
if (chdir(path) != 0) {
printf("failed to change working directory to \"%s\"\n", path);
return;
}
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
if ( (strcmp(entry->d_name, ".") != 0) && (strcmp(entry->d_name, "..") != 0) ) {
struct stat fileInfo;
if (stat(entry->d_name, &fileInfo) == 0) {
if (S_ISDIR(fileInfo.st_mode)) {
recurse(entry->d_name);
chdir("..");
} else
if (S_ISREG(fileInfo.st_mode)) {
/* print the file name */
char fullPath[ 1024 ] = {'\0'};
getcwd(fullPath, sizeof(fullPath));
strcat(fullPath, entry->d_name);
printf("found:%s\n", fullPath);
}
}
}
}
closedir(dir);
}
Any ideas? I seem to remember seeing a tinysmb recurse example someplace, but I can't find it now.|
Re: SMB recursive directory scan March 26, 2009 06:16AM | Registered: 17 years ago Posts: 441 |
|
Re: SMB recursive directory scan March 26, 2009 07:13AM | Registered: 17 years ago Posts: 78 |
|
Re: SMB recursive directory scan March 26, 2009 10:24PM | Registered: 17 years ago Posts: 441 |
|
Re: SMB recursive directory scan March 27, 2009 10:52AM | Registered: 17 years ago Posts: 78 |
#include < stdio.h >
#include < stdlib.h >
#include < unistd.h >
#include < string.h >
#include < gccore.h >
#include < network.h >
#include < errno.h >
#include < wiiuse/wpad.h >
#include < fat.h >
#include < smb.h >
#include < sys/stat.h >
#include < dirent.h >
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
void recurse(char *path) {
DIR *dir = opendir(path);
if (!dir) {
printf("failed to open directory \"%s\"\n", path);
return;
}
if (chdir(path) != 0) {
printf("failed to change working directory to \"%s\"\n", path);
return;
}
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
if ( (strcmp(entry->d_name, ".") != 0) && (strcmp(entry->d_name, "..") != 0) ) {
struct stat fileInfo;
if (stat(entry->d_name, &fileInfo) == 0) {
if (S_ISDIR(fileInfo.st_mode)) {
recurse(entry->d_name);
chdir("..");
} else
if (S_ISREG(fileInfo.st_mode)) {
/* print the file name */
char fullPath[ 1024 ] = {'\0'};
getcwd(fullPath, sizeof(fullPath));
strcat(fullPath, entry->d_name);
printf("found:%s\n", fullPath);
}
}
}
}
closedir(dir);
}
int main(int argc, char **argv) {
VIDEO_Init();
WPAD_Init();
rmode = VIDEO_GetPreferredMode(NULL);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
/* Init the fat file system */
fatInitDefault();
/* Init smb file system */
printf(" init network...");
while (net_init() == -EAGAIN);
char myIP[16];
if (if_config(myIP, NULL, NULL, true) < 0) {
printf("failed to init network interface\n");
exit(EXIT_FAILURE);
}
printf("%s\n", myIP);
if (smbInit("guest", "guest", "Music", "192.168.0.1") != true) {
printf(" failed to connect to smb share\n");
exit(EXIT_FAILURE);
}
printf(" connected to smb share\n");
recurse("smb:/");
printf("\n DONE\n");
while(1) {
WPAD_ScanPads();
u32 pressed = WPAD_ButtonsDown(0);
if ( pressed & WPAD_BUTTON_HOME ) exit(0);
VIDEO_WaitVSync();
}
return 0;
}
|
Re: SMB recursive directory scan April 04, 2009 05:20AM | Registered: 17 years ago Posts: 441 |
|
Re: SMB recursive directory scan April 04, 2009 06:01AM | Registered: 17 years ago Posts: 78 |