#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
int main(int argc ,char *argv[])
{
struct stat s;
struct stat s_dt ;
DIR *dir;
struct dirent *dt;
int i = 0;
gchar *start_prefix[4] = { "DISK_", "USB_", "SD_", "cdrom" } ;
if(stat(ROOT_DIR, &s) < 0)
{
perror("stat");
return 1 ;
}
if(S_ISDIR(s.st_mode))
{
if((dir = opendir(ROOT_DIR)) == NULL)
{
printf("opendir %s/%s error/n");
return 1;
}
if(chdir(ROOT_DIR) < 0)
{
printf("chdir error/n");
return 1;
}
while((dt = readdir(dir)) != NULL)
{
if(stat(dt->d_name, &s_dt) < 0)
{
perror("stat");
return 1;
}
if(S_ISDIR(s_dt.st_mode))
{
for(i=0; i<4; i++)
{
if( g_str_has_prefix(dt->d_name, start_prefix[i]) )
{
printf("dirname = /%s/n", dt->d_name);
}
}
}
}
}
}
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
int main(int argc ,char *argv[])
{
struct stat s;
struct stat s_dt ;
DIR *dir;
struct dirent *dt;
int i = 0;
gchar *start_prefix[4] = { "DISK_", "USB_", "SD_", "cdrom" } ;
if(stat(ROOT_DIR, &s) < 0)
{
perror("stat");
return 1 ;
}
if(S_ISDIR(s.st_mode))
{
if((dir = opendir(ROOT_DIR)) == NULL)
{
printf("opendir %s/%s error/n");
return 1;
}
if(chdir(ROOT_DIR) < 0)
{
printf("chdir error/n");
return 1;
}
while((dt = readdir(dir)) != NULL)
{
if(stat(dt->d_name, &s_dt) < 0)
{
perror("stat");
return 1;
}
if(S_ISDIR(s_dt.st_mode))
{
for(i=0; i<4; i++)
{
if( g_str_has_prefix(dt->d_name, start_prefix[i]) )
{
printf("dirname = /%s/n", dt->d_name);
}
}
}
}
}
}