int main() { File* file1 = new File("a.txt", 10); // 파일은 자신의 크기가 있습니다. File* file2 = new File("b.txt", 20); File* file3 = new File("c.txt", 30); Folder* root = new Folder("ROOT"); // 폴더는 자신의 크기가 없습니다. Folder* folder1 = new Folder("A"); Folder* folder2 = new Folder("B"); folder1->add(file1); folder2->add(file2); root->add(file3); root->add(folder1); root->add(folder2); cout << file1->getSize() << endl; // 파일은 크기를 구할 수 있습니다. cout << root->getSize() << endl; // 폴더도 크기를 구할 수 있습니다. // print hierarchy cout << endl; root->print(); }
void populate(Folder &folder) { // Get a list of the files in this directory. Archive::Names names; archive().listFiles(names, basePath); DENG2_FOR_EACH(Archive::Names, i, names) { if(folder.has(*i)) { // Already has an entry for this, skip it (wasn't pruned so it's OK). continue; } String entry = basePath / *i; std::auto_ptr<ArchiveEntryFile> archFile(new ArchiveEntryFile(*i, archive(), entry)); // Write access is inherited from the main source file. if(allowWrite) archFile->setMode(File::Write); // Use the status of the entry within the archive. archFile->setStatus(archive().entryStatus(entry)); // Create a new file that accesses this feed's archive and interpret the contents. File *f = folder.fileSystem().interpret(archFile.release()); folder.add(f); // We will decide on pruning this. f->setOriginFeed(&self); // Include the file in the main index. folder.fileSystem().index(*f); } // Also populate subfolders. archive().listFolders(names, basePath); for(Archive::Names::iterator i = names.begin(); i != names.end(); ++i) { folder.fileSystem().makeFolder(folder.path() / *i, FS::InheritPrimaryFeed); } }