LINUX.ORG.RU

lstat


0

0

......................................

	struct dirent *entry;
	DIR *dir;
	struct stat st;
	dir =  opendir(path.c_str());
	while ( (entry = readdir (dir)) != NULL)
	{
		const char * type;
		std::string tmp( entry->d_name);
//		if ( (tmp == ".") || (tmp == ".."))
//			continue;
		stat (path.c_str(), &st);
		if ( S_ISREG (st.st_mode))
			std::cout << "\n\tfile=" << tmp << "\tsize=" << st.st_size << std::endl;
		if ( S_ISDIR (st.st_mode))
			std::cout << "\n\tdir=" << tmp << "\tsize=" << st.st_size << std::endl;

	};
	closedir(dir);
.....................................................

stalcker@stalcker:/work/vacancy$ ./out ./1/ ./2/

        dir=.   size=1024

        dir=..  size=1024

        dir=1_2 size=1024

        dir=1_1 size=1024

        dir=main.cpp    size=1024

        dir=.   size=1024

        dir=..  size=1024

        dir=2_1 size=1024

        dir=2_2 size=1024

        dir=main.d      size=1024

При чтении каталогов, файлы в них определяются не как файлы, 
а как каталоги. Помогите разобраться.
anonymous

> stat (path.c_str(), &st);

Ты всегда вызываешь stat для каталога. Сделай примерно так:

stat((path + '/' + entry->d_name).c_str(), &st);

nobody ★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.