本文整理汇总了C++中FileManager::searchFiles方法的典型用法代码示例。如果您正苦于以下问题:C++ FileManager::searchFiles方法的具体用法?C++ FileManager::searchFiles怎么用?C++ FileManager::searchFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::searchFiles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processMessages
// process messages, send back a reply when a file successfully received
void FileProcessingCommunicator::processMessages(){
try{
while (true){
Message msg = bq.deQ(); Header hdr = msg.getHdr();
string addr = hdr.getAddress(), srcAddr = hdr.getSrcAddr(), srcPort = hdr.getSrcPort(), port = hdr.getPort(), cmd = hdr.getCmd(), content = hdr.getAttrib("filename");
AbstractDispatcher& dispatcher = AbstractDispatcher::getInstance();
Message msgReply; Header hdrReply;
hdrReply.setAddr(srcAddr, srcPort);
hdrReply.setSrcAddr(addr, port);
if (content == "stop"){
sout << "\n Stopping file processing communicator \n";
break;
}
if (cmd == "get_file"){//download
Folder folder; string destDir = folder.getUploadDir(); FileManager mgr;
std::vector<std::string> files = mgr.searchFiles(destDir, "*.*", false);
//Send all files in the upload directory
for (string path : files){
hdrReply.setTargetCommunicator("CLientEchoCommunicator");
hdrReply.setCmd("send_file");
hdrReply.setAttrib("filename", path);
hdrReply.setAttrib("msg", "download_reply");
msgReply.setHdr(hdrReply);
dispatcher.postMessage(msgReply);
}
}
else{//upload
string src_file = hdr.getAttrib("src_file_path");
FileInfo fileinfoDest(content); FileInfo fileinfoSrc(src_file); //string cmd = hdr.getAttrib("send_file_begin");
string printMsg = "\n Received File " + src_file + " of SIZE = " + std::to_string(fileinfoSrc.size()) + " from " + srcAddr + ":" + srcPort + " and saved at " + content + " with SIZE = " + std::to_string(fileinfoDest.size()) + " \n\n";
sout << printMsg;
hdrReply.setTargetCommunicator("CLientEchoCommunicator");
string strMsg = "Response for received file " + Path::getName(src_file);
hdrReply.setAttrib("msg", strMsg);
hdrReply.setCmd("echo_msg");
msgReply.setHdr(hdrReply);
dispatcher.postMessage(msgReply);
}
}
}catch (exception e){
sout << e.what();
}
}
示例2: sr
//String processing instance constructor
StringProcessor::StringProcessor(Message msg){
try{
request = msg;
/*Timer timer;
long long time_stamp = timer.getCurrentTime();
request.getHdr().setAttrib("start_time", to_string(time_stamp));*/
Header hdr = msg.getHdr();
//srchDir = hdr.getAttrib("directory");
Folder folder;
srchDir = folder.getUploadDir();
srchString = hdr.getAttrib("search_string");
numThreads = atoi(hdr.getAttrib("no_of_threads").c_str());
if (numThreads == 0){
numThreads = 1;
}
FileManager mgr;
std::vector<std::string> files = mgr.searchFiles(srchDir, "*.*", false);
numFiles = 0;
std::string exclude_exts[] = { "zip", "exe", "jpg", "jpeg", "png", "JPG", "JPEG", "EXE" };//exclude extendions for string search
for (auto file : files){
std::string extension = Path::getExt(file);
bool isSkip = false;
for (auto ext : exclude_exts){
if (ext == extension){
isSkip = true;
break;
}
}
if (isSkip){
continue;
}
SearchResult sr(file);
bqIn.enQ(sr);
numFiles++;
}
}
catch (exception e){ sout << e.what(); }
}