Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. IO;
Using system. Text. regularexpressions;
Namespace readfiles
{
Public partial class formnode: Form
{
Public formnode ()
{
Initializecomponent ();
}
private void btnsubmit_click (Object sender, eventargs e)
{< br> If (txtnode. text. tostring () = "" | txtnode. text. tostring () = NULL | txtnode. text. tostring () = string. empty)
{< br> MessageBox. show ("Enter the measurement point to be queried! "," Non-empty measurement point warning! ");
return;
}
Else if (txtpath. text. tostring () = "" | txtpath. text. tostring () = NULL | txtpath. text. tostring () = string. empty)
{
MessageBox. Show ("Enter the folder path! "," Warning about path not empty! ");
Return;
}
Else if (txtnode. Text = "'" | txtnode. Text = "'")
{
MessageBox. Show ("contains invalid characters. Please try again! "," Illegal character warning! ");
}
Else
{
String Path = txtpath. Text. tostring () + "\\";
Findfile (PATH );
}
# Region test
// Int COUNT = 0;
// Filestream FS = new filestream ("", filemode. Open, fileaccess. Read );
// Streamreader sr = new streamreader (FS, encoding. getencoding ("gb2312 "));
// String line = Sr. Readline ();
// For (INT I = 0; line! = NULL; I ++)
//{
// If (line. Contains ("8002") = true)
//{
// Count ++;
// Lisinfo. Items. Add (line );
//}
// Line = Sr. Readline ();
//}
// Sr. Close ();
// Fs. Close ();
# Endregion
}
Public void findfile (string dirpath) // The dirpath parameter is the specified directory.
{
// Search for files in the specified directory and subdirectory, and list subdirectories and files in listbox1
String filename = "";
Directoryinfo dir = new directoryinfo (dirpath );
Try
{
Foreach (directoryinfo D in Dir. getdirectories () // find the subdirectory
{
Findfile (DIR + D. tostring () + "\\");
Lisinfo. Items. Add (DIR + D. tostring () + "\"); // Add the directory name in listbox1
}
Foreach (fileinfo F in Dir. getfiles ("*. dat") // find the file
{
// Lisinfo. Items. Add (DIR + F. tostring (); // Add the file name in listbox1
// Lisinfo. Items. Add (F. tostring (); // Add the file name in listbox1
Filename = f. tostring ();
Int COUNT = 0;
Filestream FS = new filestream (txtpath. Text + "\" + filename, filemode. Open, fileaccess. Read );
Streamreader sr = new streamreader (FS, encoding. getencoding ("gb2312 "));
String line = Sr. Readline ();
For (INT I = 0; line! = NULL; I ++)
{
If (line. Contains (txtnode. Text. tostring () = true)
{
Count ++;
Lisinfo. Items. Add (line );
}
Line = Sr. Readline ();
}
Sr. Close ();
FS. Close ();
}
}
Catch (exception E)
{
MessageBox. Show (E. message, "error capture prompt! ");
}
}
///
// open the data loading window
///
///
//
private void btnload_click (Object sender, eventargs e)
{< br> loadfiles LD = new loadfiles ();
lD. showdialog ();
}
private void btnsound_click (Object sender, eventargs e)
{< br> sound so = new sound ();
SO. showdialog ();
}< BR >}