Search for specific text in text document
What I am doing is creating a simple login and register system. I am going to save the information of each user into a text or ".dat" format and have them placed into a folder called "accounts".
The small problem that I have is the "Forgot Password" option. I can't think of how to search all the documents for the e-mail or the username.
So basically I need to know if it is possible to do a small search for the e-mail through all the documents in the "accounts" folder.
**I know another option may be databases...but I don't completely know how to use these.
**I have general knowledge of arrays
Don't know what else to say, just need a general search function I guess ^_^
Thanks for the help:D
Re: Search for specific text in text document
You should be encrypting those files, but try this:
vb.net Code:
Public Function FindTextInDirectory(ByVal TextToFind As String, ByVal ParentFolder As String, ByVal SearchOption As IO.SearchOption) As String()
If Not IO.Directory.Exists(ParentFolder) Then Throw New IO.FileNotFoundException(ParentFolder + " does not exist.")
Try
Dim Files As New List(Of String)
For Each File As String In IO.Directory.GetFiles(ParentFolder, "*.dat", SearchOption)
Try
For Each Line As String In IO.File.ReadAllLines(File)
If Line.ToUpper().Contains(TextToFind.ToUpper()) Then
Files.Add(File)
End If
Next
Catch ex As Exception
Throw ex
End Try
Next
Return files.ToArray()
Catch ex As Exception
Throw ex
End Try
End Function
You can use it like this:
vb.net Code:
For Each file As String In Me.FindTextInDirectory("
[email protected]", "C:\Folder", IO.SearchOption.TopDirectoryOnly)
MessageBox.Show(file) ' path to file that contained text
Next
Re: Search for specific text in text document
Quote:
Originally Posted by
Shadow45o
I am going to save the information of each user into a text or ".dat" format and have them placed into a folder called "accounts".
I wouldn't recommend that - better (and safer) way is to use database (and you are aware of it) that stores encrypted information.
Secured, convenient and no hassle search.