#include "stdafx.h"
#include <fstream>
#include <iostream>
#include<list>
#include <string>
#include <sstream>
#include <vector>
#include<io.h>
using namespace std;
typedef std::vector<std::string> StringList;
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)
{
long 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);
}
}
int main()
{
string DATA_DIR = "D:/WWY/ForMP/imgs";
vector<string> files;
char * DistAll = "AllFiles.txt";
getAllFiles(DATA_DIR, files);
int size = files.size();
int FaiNum = 0;
cout << size << endl;
int Max = 0;
int k = 0;
for (int i = 0; i<size; i++)
{
vector<string> test;
test = splitstr(files[i], '_');
test[3] = test[3].substr(0, test[3].length()-4);
if (test[3].length() > Max) {
Max=test[3].length();
cout <<"第"<<i<<" 次"<< "max=" << Max << endl;
}
}
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-40007.html