static void Main(string[] args)
{
StringPath= String. Format (@ "c:\users\administrator\desktop\{0}", @ "Shenzheng");//root directory
List<string> filepaths =getalldirectories(path);//Returns a collection of all files (including paths) under the root directory
foreach (var item in filepaths)
{
StreamReader read = new StreamReader (item, ENCODING.UTF8);//Get file stream based on file path
String fileName = Path.getfilenamewithoutextension (item);//File name
String FilePath = Path.getdirectoryname (item);//folder where the files are located
if (!read. Endofstream)//Whether read completed
{
string aline = read. ReadToEnd ();//Read all------//string aline = read. ReadLine (); read one line
Console.WriteLine (read. ReadLine ());
String Keystar = "* * *";//keyword start
String ketend = "&&&";//keyword end//get string between
int star = Aline. IndexOf (Keystar) + keystar.length;//plus the number of bits that the Keystar occupies
int end = Aline. IndexOf (Ketend);
if (Star > 0 && end > Star)//keyword not found
{
String newstr = Aline. Substring (Star, End-star);
Console.WriteLine (NEWSTR);//Print to the console to see if the desired information is intercepted
Console.WriteLine (FileName + "Print Complete");
Char[] dd = new char[] {'] ', ', '};
string[] STRs = newstr. Split (new string[] {"Split String"}, Stringsplitoptions.removeemptyentries);//Divide the string you want by the rule to get a string collection
StreamWriter SW = new StreamWriter (@ "C:\Users\Administrator\Desktop\out\" + fileName + "process. txt", false);//Output directory and file name definition
for (int i = 0; i < STRs. Count (); i++)
{
Console.WriteLine (Strs[i] + "," + (i + 1). ToString ());//Print to console
Sw. WriteLine (Strs[i] + "," + (i + 1). ToString ());//write to file
Sw. Flush ();//Empty StreamWriter cache, otherwise it will not be fully written
Thread.Sleep (20);
}
Console.WriteLine (FileName + "write complete");
Console.readkey ();
}
Else
{
Console.WriteLine ("Current Document" + FileName + "No data conforming to the rules, skip!") ");
}
}
}
static list<string> fileslist = new list<string> ();
public static list<string>getalldirectories(String RootPath)
{
string[] subpaths = directory.getdirectories (RootPath);//Get all subdirectories
foreach (string path in subpaths)
{
GetAllDirectories (path);//Do the same thing as the root directory for each word directory: The subdirectory is found and the file name of the current directory is stored in the list
}
string[] files = directory.getfiles (RootPath);
foreach (string file in files)
{
Fileslist.add (file);//The full file name in the current directory is saved to the file list
}
return fileslist;
}
}
C #. NET gets all the files under the folder (multi-layered recursion), and gets the interval data (Jsion,xml and other data) written out to the processing file, learning to share ~