Had to do some legacy coding in Turbo C++ for school project, when I ran into a problem using dirent.h
#include <dirent.h>
#include <stdio.h>
#include <iostream.h>
void ls(char *searchstring)
{
DIR *directory_list;
struct dirent *dentry;
directory_list = opendir (searchstring);
if (directory_list != NULL)
{
while ((dentry = readdir (directory_list)) != NULL)
{
cout << dentry->d_name << endl;
}
}
closedir (directory_list);
}
void main()
{
char searchstring[128];
gets(searchstring);
cout << "list of files under " << searchstring;
ls(searchstring);
}
This code should ideally list all file and folder names in a directory. But I get this:
It seems that the
d_name
field doesn't seem to store file names larger than 9 characters(including null) and instead truncates it with a '~' and a number.
I read something about NAME_MAX bound length for string in dirent structure, but I can't find anymore information about it anywhere on the web.
I want the full file and folder names instead, and sorry I am bound to use the ancient Turbo C++.