-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.cpp
44 lines (38 loc) · 1.2 KB
/
ls.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
34
35
36
37
38
39
40
41
42
43
44
// ls : display all the files and directories in the working dir.
#include <iostream>
#include <Windows.h>
#include <filesystem> // to get file lists
#include "ls.h"
namespace fs = std::experimental::filesystem; // to get file lists
void ls(std::string path) {
std::cout << "List of files" << std::endl;
std::cout << "----- ------ -------------------------------------------" << std::endl;
printf("----D%10d %s\n", 0, ".");
printf("----D%10d %s\n", 0, "..");
for (const auto & entry : fs::directory_iterator(path))
{
// file attributes(RSHAD)
DWORD fileAttri = GetFileAttributes((entry.path().filename().wstring().c_str()));
//R
if (fileAttri & 0x01) std::cout << "R";
else std::cout << "-";
// S
if (fileAttri & 0x04) std::cout << "S";
else std::cout << "-";
// H
if (fileAttri & 0x02) std::cout << "H";
else std::cout << "-";
// A
if (fileAttri & 0x20) std::cout << "A";
else std::cout << "-";
// D
if (fileAttri & 0x10) std::cout << "D";
else std::cout << "-";
// file size
if (!fs::is_directory(entry.path()))
printf("%10d ", fs::file_size(entry.path()));
else printf("%10d ", 0);
// file name
std::cout << entry.path().filename() << std::endl;
}
}