#include <unistd.h>
int file_exist(const char* filename)
{
if( access( filename, F_OK ) == 0 )
return 1; //exist
else
return 0;
}
2. stat
#include <sys/stat.h>
/*
* return 0 if the file exist, otherwise return 1
*/
int file_exist(const char* filename){
struct stat buffer;
int exist = stat(filename,&buffer);
if(exist == 0)
return 0;
else // -1
return 1;
}
3. glob_t
#include <glob.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
int main (void)
{
glob_t globfiles;
glob("/home/ubuntu/*.wav", 0, NULL, &globfiles);
printf("%ld\n", globfiles.gl_pathc);
int i=0;
for(i=0;i<globfiles.gl_pathc;i++)
{
//int fd = open(globfiles.gl_pathv[0], O_RDONLY);
printf("%s\n", globfiles.gl_pathv[i]);
}
globfree(&globfiles);
return 0;
}
沒有留言:
張貼留言