#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include <string>
#include <string.h>
#include <sys/stat.h>
#include <sstream>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <fstream>
#include<list>
#include <string>
#include <sstream>
#include <vector>
#include<io.h>
#include<stdlib.h>
using namespace std;
void getAllFiles(string path, vector<string>& files);
typedef std::vector<std::string> StringList;
StringList splitstr(const std::string& str, char tag);
string& replace_all(string& str, const string& old_value, const string& new_value)
{
while (true)
{
string::size_type pos(0);
if ((pos = str.find(old_value)) != string::npos)
{
str.replace(pos, old_value.length(), new_value);
}
else { break; }
}
return str; }
int main()
{
string DATA_DIR = "D:/NewForWwy/workspaceForMine/DATASET/VOCofMine";
vector<string> files;
char * DistAll = (char *)"AllFiles.txt";
getAllFiles(DATA_DIR, files);
int size = files.size();
int FaiNum = 0;
for (int i = 0; i<size; i++)
{
string str = files[i].substr(files[i].length()-4, files[i].length());
if (str == ".jpg") {
cout << files[i] << endl;
string dst = string("D:\\NewForWwy\\workspaceForMine\\DATASET\\VOCofMine\\test");
replace_all(files[i], "/", "\\");
string name = "move " + files[i] + " " + dst;
const char *des_name = name.c_str();
cout << des_name << endl;
system(des_name);
}
}
return 0;
}
StringList splitstr(const std::string& str, char tag)
{
StringList li;
std::string subStr;
for (size_t i = 0; i < str.length(); i++)
{
if (tag == str[i])
{
if (!subStr.empty())
{
li.push_back(subStr);
subStr.clear();
}
}
else
{
subStr.push_back(str[i]);
}
}
if (!subStr.empty())
{
li.push_back(subStr);
}
return li;
}
void getAllFiles(string path, vector<string>& files)
{
intptr_t hFile = 0;
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
files.push_back(p.assign(path).append("/").append(fileinfo.name));
getAllFiles(p.assign(path).append("/").append(fileinfo.name), files);
}
}
else
{
files.push_back(p.assign(path).append("/").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}