研究了学习了一下这个功能,放上自己调试后的代码
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
int stat(
const char *path,
struct _stat *buffer
);
bool GetFileInfo(std::string path, std::vector<std::string> &filenames)
{
string str_path;
const char* p_path;
struct stat buf;
char timebuf[26];
int result;
DIR *pDir;
struct dirent *ptr;
if (!(pDir = opendir(path.c_str())))
{
LOG_INFO << "Folder doesn't exit !";
return false;
}
while ((ptr = readdir(pDir)) != 0)
{
if ((ptr->d_type == 8) && 0 == (strcmp(strchr(ptr->d_name, '.'), ".mp3")))
{
filenames.push_back(ptr->d_name);
str_path = audio_dir + "/" + ptr->d_name;
p_path = str_path.data();
result = stat( p_path, &buf );
filenames.push_back( to_string(buf.st_size) );
filenames.push_back( ctime(&buf.st_mtime) );
}
}
closedir(pDir);
return true;
}