-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistDirectoryContents.cpp
33 lines (32 loc) · 1.27 KB
/
listDirectoryContents.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "filesystem.h"
void FileSystem::listDirectoryContents() {
/*
objective: prints all files and directories in disk
input: None
return: None
output: list of files and directories in disk
*/
char buf[kSectorSize];
TypeCastEntry entry;
for (int i = 0; i < sectorsForDir; ++i) {
readSector(currentDir + i, buf);
for (int j = 0; j < kSectorSize; j += 32) {
for (int k = 0; k < 32; ++k) {
entry.str[k] = buf[j+k];
}
if (entry.entry.type == 'F') {
std::cout << std::left << std::setw(22) <<
entry.entry.name << std::right <<
std::setw(10) << entry.entry.size << " bytes" << std::endl;
} else if (entry.entry.type == 'f') {
std::cout << std::left << std::setw(22) << "(" <<
entry.entry.name << ")" << std::right <<
std::setw(10) << entry.entry.size << " bytes" << std::endl;
} else if ((entry.entry.type == 'D')) {
std::cout << std::left << KBLU << std::setw(22) <<
entry.entry.name << KRST << std::right <<
std::setw(10) << "[DIR]" << std::endl;
}
}
}
}