从多层级的目录文件中查找字符串
从多层级的目录文件中查找指定的字符串
package com.vfsd.core; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class StringFind { public static void main(String[] args) throws IOException { //File dir1 = new File("O:\\OpenSceneGraph\\OpenSceneGraph_3_6_install\\"); //File dir1 = new File("E:\\OpenSceneGraph\\OpenSceneGraph_3_4_install\\"); //File dir1 = new File("K:\\Qt\\Qt5.12.2\\5.12.2\\msvc2015_64\\"); //File dir1 = new File("E:\\Geos\\geos_3_5_install\\"); //File dir1 = new File("E:\\GDAL\\gdal212_install\\"); //File dir1 = new File("E:\\CURL\\curl_install\\"); //File dir1 = new File("E:\\OpenSceneGraph\\3rdParty\\v140-x64\\"); //File dir1 = new File("E:\\Opencv\\opencv_3_4_6_install\\"); //File dir1 = new File("E:\\boost_1_70_0\\vc14-x64\\"); //File dir1 = new File("E:\\IFCPlus"); File dir1 = new File("E:\\OpenFace\\OpenFace-master2"); //searchString("<iostream>",dir1); //searchString("<sstream>",dir1); //searchString("<fstream>",dir1); //searchString("<ostream>",dir1); searchString("fs::",dir1); } public static void searchString(String strFind,File dirParam) throws IOException { File []files1 = dirParam.listFiles(); for(int k=0;k<files1.length;k++) { File fileIndex = files1[k]; //System.out.println(fileIndex.getName()); if(fileIndex.isDirectory()) { searchString(strFind,fileIndex); }else { getFileContent(strFind,fileIndex); } } } public static void getFileContent(String strFind,File fileParam) throws IOException { try { FileReader fileReader1 = new FileReader(fileParam); BufferedReader bufferedReader1 = new BufferedReader(fileReader1); String lineStr1=""; while((lineStr1=bufferedReader1.readLine())!=null) { if(lineStr1.contains(strFind)) { System.out.println(fileParam.getPath()+"\t\t\t\t\t"+lineStr1); } } bufferedReader1.close(); fileReader1.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
输出:
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\include\FaceAnalyserParameters.h fs::path root;
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyser.cpp fs::path root = fs::path(model_loc).parent_path();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyser.cpp fs::path root = fs::path(au_model_location).parent_path();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp this->root = fs::path(arguments[0]).parent_path();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path config_path = fs::path(CONFIG_DIR);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path model_path = fs::path(this->model_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(root/model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(config_path/model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path config_path = fs::path(CONFIG_DIR);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path model_path = fs::path(this->model_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(root / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(config_path / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path config_path = fs::path(CONFIG_DIR);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path model_path = fs::path(this->model_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(root / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(config_path / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path config_path = fs::path(CONFIG_DIR);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp fs::path model_path = fs::path(this->model_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(root / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\FaceAnalyser\src\FaceAnalyserParameters.cpp else if (fs::exists(config_path / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\FaceDetectorMTCNN.cpp fs::path root = fs::path(location).parent_path();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorModel.cpp fs::path root = fs::path(clnf_location).parent_path();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorModel.cpp fs::path root = fs::path(main_location).parent_path();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorModel.cpp std::string root_loc = fs::path(main_location).parent_path().string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp fs::path root = fs::path(arguments[0]).parent_path();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp fs::path config_path = fs::path(CONFIG_DIR);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp fs::path model_path = fs::path(model_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(root/model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(config_path/model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp model_path = fs::path(haar_face_detector_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(root / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(config_path / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp model_path = fs::path(mtcnn_face_detector_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(root / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(config_path / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp fs::path config_path = fs::path(CONFIG_DIR);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp fs::path model_path = fs::path(model_location);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp fs::path root_path = fs::path(root);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp if (fs::exists(model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(root_path / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\LandmarkDetector\src\LandmarkDetectorParameters.cpp else if (fs::exists(config_path / model_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp std::string separator = std::string(1, fs::path::preferred_separator);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp fs::path image_directory(directory);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp std::vector<fs::path> file_in_directory;
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp copy(fs::directory_iterator(image_directory), fs::directory_iterator(), back_inserter(file_in_directory));
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp for (std::vector<fs::path>::const_iterator file_iterator(file_in_directory.begin()); file_iterator != file_in_directory.end(); ++file_iterator)
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp fs::path current_file = *file_iterator;
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp fs::path bbox_file = bbox_directory / current_file.filename().replace_extension("txt");
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\ImageCapture.cpp if (fs::exists(bbox_file))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp if (!fs::exists(output_path))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp bool success = fs::create_directories(output_path);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp fs::path of_det_name(out_name);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp of_det_name = fs::path(record_root) / fs::path(out_name + "_of_details.txt");
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp if (!fs::path(input_filename_full).is_absolute())
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp input_filename_full = fs::canonical(input_filename_relative).string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp hog_filename = (fs::path(record_root) / hog_filename).string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp this->media_filename = (fs::path(record_root) / this->media_filename).string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp this->media_filename = (fs::path(record_root) / this->media_filename).string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp this->aligned_output_directory = (fs::path(record_root) / this->aligned_output_directory).string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp if (fs::is_directory(in_filename))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp out_name = fs::canonical(in_filename).filename().string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp out_name = fs::path(in_filename).filename().replace_extension("").string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp record_root = (fs::path(record_root) / fs::path(arguments[i + 1])).remove_filename().string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp out_name = fs::path(fs::path(arguments[i + 1])).replace_extension("").filename().string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp if (fs::is_directory(in_filename))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp out_name = fs::canonical(fs::path(in_filename)).filename().string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp out_name = fs::path(in_filename).filename().replace_extension("").string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp csv_filename = (fs::path(record_root) / csv_filename).string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\RecorderOpenFace.cpp std::string out_file = (fs::path(aligned_output_directory) / fs::path(std::string(name) + params.imageFormatAligned())).string();
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\SequenceCapture.cpp std::string separator = std::string(1, fs::path::preferred_separator);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\SequenceCapture.cpp fs::path image_directory(directory);
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\SequenceCapture.cpp if (!fs::exists(image_directory))
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\SequenceCapture.cpp std::vector<fs::path> file_in_directory;
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\SequenceCapture.cpp copy(fs::directory_iterator(image_directory), fs::directory_iterator(), back_inserter(file_in_directory));
E:\OpenFace\OpenFace-master2\OpenFace-master\lib\local\Utilities\src\SequenceCapture.cpp for (std::vector<fs::path>::const_iterator file_iterator(file_in_directory.begin()); file_iterator != file_in_directory.end(); ++file_iterator)