move listdir to separate file
This commit is contained in:
parent
f82035df55
commit
9a6177092f
29
src/fs.cpp
Normal file
29
src/fs.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "fs.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<string> cellar::fs::listdir(string path) {
|
||||
vector<string> result;
|
||||
boost::filesystem::path cwd(path);
|
||||
boost::filesystem::directory_iterator iter_end;
|
||||
|
||||
for (boost::filesystem::directory_iterator iter_cwd(cwd); iter_cwd != iter_end; ++iter_cwd) {
|
||||
try {
|
||||
string item = iter_cwd->path().filename().native();
|
||||
|
||||
result.push_back(item);
|
||||
}
|
||||
catch (const exception& exc) {
|
||||
cout << "[1;31mfuck[0m" << endl;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
16
src/fs.hpp
Normal file
16
src/fs.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef __FS_HPP
|
||||
#define __FS_HPP
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cellar {
|
||||
namespace fs {
|
||||
extern vector<string> listdir(string path);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __FS_HPP
|
Loading…
Reference in New Issue
Block a user