1. c++
1.1 得到给定文件夹下所有文件的路径
#include <dirent.h>
#include <string>
#include <vector>
#include "string.h"
using namespace std;
void GetFileNames(string path,vector<string>& filenames)
{
DIR *pDir;
struct dirent* ptr;
if(!(pDir = opendir(path.c_str()))){
cout<<"Folder doesn't Exist!"<<endl;
return;
}
while((ptr = readdir(pDir))!=0) {
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0){
filenames.push_back(path + "/" + ptr->d_name);
}
}
closedir(pDir);
}
1.2 以给定符号分割字符串
#include <string>
#include <vector>
using namespace std;
void split(const string& s,vector<int>& sv,const char flag = ' ') {
sv.clear();
istringstream iss(s);
string temp;
while (getline(iss, temp, flag)) {
sv.push_back(stoi(temp));
}
return;
}
1.3 生成随机数
#include<random>
default_random_engine e;
uniform_real_distribution<double> u(-3.5, 3.5);
2. python
3. 终端命令
3.1 获得文件夹下所有文件绝对路径并保存到文件
ls | sed "s:^:`pwd`/:" > paths.txt