---
# System prepended metadata

title: dir function
tags: [codebook]

---

---
tags: codebook
---

{%hackmd theme-dark %}

# dir function
```cpp=
#include<sys/types.h>
#include<sys/stat.h>
#include<dirent.h>
#include<fcntl.h>
#include<unistd.h>
using namespace std;
```
```cpp=
vector<string> dir(const string& path=".\\"){
	vector<string> v;
	DIR *dirptr;
	struct dirent *direntptr;
	dirptr=opendir(path.data());
	if(!dirptr) v.push_back("error.");
	else{
		direntptr=readdir(dirptr);
		direntptr=readdir(dirptr);
		while(direntptr=readdir(dirptr),direntptr)
			v.push_back(direntptr->d_name);
	}
	return v;
}
```