C++ tinyDir lib issue

Started by
1 comment, last by noatom 8 years, 10 months ago

I'm using the tinyDir header available here:

https://github.com/cxong/tinydir

The problem is, every time I open a folder to find the directories/files inside it, there are always 2 elements that appear to be files, but are not.

The code I use:


        tinydir_dir dir;
	int i;
	tinydir_open_sorted(&dir, directory.c_str());

	for (i = 0; i < dir.n_files; i++)
	{
		tinydir_file file;
		tinydir_readfile_n(&dir, &file, i);

		printf("%s", file.name);
		if (file.is_dir)
		{
			printf("/");
		}
		printf("\n");
	}

	tinydir_close(&dir);

If I use a path like: C:\\test and that folder only has 1 file in it, the output is:

./
../
file.txt
The first 2 elements appear to be some kind of path to parent directories. Why do the first 2 lines appear?

Advertisement

Why do the first 2 lines appear?


Ignore them.


Technical details:
"." and ".." are symbolic links to the current and parent folders respectively. Think of a tree, for a node, these "child nodes" are pointers to the current node and it's parent node. It's what makes path names such as "./omg/../../wtf/bbq/your_mom" possible.

Ok. Thank you for that detail!

This topic is closed to new replies.

Advertisement