Basically I am creating a basic shell program for a class project. I am stuck on iterating through the files/folders within a directory.
My error is in the function DisplayDirectoryContents()
class Directory
{
private:
map<string, pair<list<Folder>, list<File> > > directoryContents;
string directoryPath;
public:
list<Folder> getFolders() {return directoryContents[directoryPath].first;}
list<File> getFiles() {return directoryContents[directoryPath].second;}
string getDirectoryPath() {return directoryPath;}
Directory()
{
directoryPath = "root/";
File *file = new File("Test");
directoryContents[directoryPath].second.push_back(*file);
}
void DisplayDirectoryContents()
{
// Get files and folders from directory
list<File> files = this->getFiles();
for(int i = 0; i < files.size(); i++)
{
cout << files->getFileName(); << Error here
}
}
};
I've tried setting this function up a few different ways but I can't seem to get the right kind of code to make it work.
I would think this would work but it's throwing me errors everytime I try and mess with the DisplayDirectoryContents() function. Does anyone have any tips that I can try to help fix this? Thanks
class File
{
string fileName;
string fileTime;
public:
string getFileTime(){return fileTime;}
string getFileName(){return fileName;}
void setFileTime(){time_t now = time(NULL);
fileTime = ctime(&now);}
void setFileName(string newFileName){fileName = newFileName;}
File(){}
File(string fName)
{
fileName = fName;
time_t now = time(NULL);
fileTime = ctime(&now);
}
void MakeFile(string fName);
void RemoveFile(string fName);
};
Folder- did you intendstd::list<Directory>instead (would make sense at least...)?DirectoryandFolderwill get two different classes for the same thing. Nothing speaks against adding otherDirectoryinstances to the parentDirectoryinstance. Wouldn't this better reflect file systems as well?