[英]Using dirent.h but files are being skipped
I have several hundred images in a folder named: 1.jpg
, 3.jpg
, 4.jpg
, 6.jpg
, 8.jpg
, 10.jpg
, 15. jpg
, .... 100.jpg
, 102.jpg
, 103.jpg
, 113.jpg
etc... 我有几百个图像文件夹名为: 1.jpg
, 3.jpg
, 4.jpg
, 6.jpg
, 8.jpg
, 10.jpg
, 15. jpg
,... 100.jpg
, 102.jpg
, 103.jpg
, 113.jpg
等...
I am using dirent.h
to iterate through the files, but somehow dirent.h
starts at 10.jpg
and the next file it delivers is suddenly 100.jpg
and then 102.jpg
, ... why does it skip some images? 我使用dirent.h
通过文件迭代,但不知何故dirent.h
开始于10.jpg
并把它送到下一个文件突然100.jpg
然后102.jpg
,...为什么它跳过一些图片?
int main (int argc, const char* argv[] )
{
cv::Mat image;
DIR *dir;
struct dirent *ent;
if ((dir = opendir ("C:\\Users\\Faraz\\Desktop\\Project\\detecting_false_positives_stuff\\face_images\\faces\\")) != NULL) {
ent = readdir (dir);
printf ("%s\n", ent->d_name);
ent = readdir (dir);
printf ("%s\n", ent->d_name);
while ((ent = readdir (dir)) != NULL) {
printf ("%s\n", ent->d_name);
std::string fullPath = std::string("C:\\Users\\Faraz\\Desktop\\Project\\detecting_false_positives_stuff\\face_images\\faces\\") + ent->d_name;
cout<<fullPath;
image = cv::imread(fullPath);
...
}
closedir (dir);
}
return 1;
} }
You'll have to sort the files yourself if you want them in order, readdir
won't do that for you. 如果需要按顺序对文件进行排序,则readdir
不会帮您排序。 See this also: Does readdir() guarantee an order? 另请参见: readdir()是否保证顺序?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.