Opening Multiple files from a directory C++ -
i trying open files directory everytime display files have these 3 dots @ top. example directory open called "my documents" output 3 dots follows . .. names.txt jobs.txt
names.txt , jobs.txt output want achieve, out.
my code
int getdoc(string doc, vector<string> &documents){ dir *dp; struct dirent *dirp; if ((dp = opendir(doc.c_str())) == null){ cout << "error(" << errno << ") opening" << doc << endl; return errno; } while ((dirp = readdir(dp)) != null){ documents.push_back(string(dirp->d_name)); } closedir(dp); return 0; }
by way use dirent.h
the 3 dots 2 directories. first 1 named '.' refers current directory. if try open it, lead same directory. example, directory c:\users\daniel
equal c:\users\daniel\.
second directory '..'. refers parent directory. c:\users
directory equivalent c:\users\daniel\..
those 2 directories not real. simulated operating system. if don't want print them, start printing list after skipping first 2 elements. 2 directories listed first.
Comments
Post a Comment