Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '--- Austin's Read/Write System v0.02 ---
- '--- 11/29/2011-11/30/2011 ---
- '
- '... Functions ...
- 'Write(File, Key, Data)
- ' -> Writes Data to the File under the Key specified
- 'Read(File, Key) [return: string]
- ' -> Reads File and returns data under the Key specified
- 'KeyExists(File, Key) [return: True/False]
- ' -> Checks if the Key exists in the File specified
- Option Explicit On
- Option Infer On
- Option Strict On
- Imports System.IO
- Module ReadWrite
- Public Sub Write(ByVal FileName As String, ByVal Key As String, ByVal Data As String)
- Dim i, a, x As Integer, dir As String, FileData As String = Nothing
- While i <> FileName.Length
- If FileName(i) = "/" Then
- dir = FileName.Substring(0, FileName.IndexOf("/", i))
- x = i + 1
- If Directory.Exists(dir) = False Then Directory.CreateDirectory(dir)
- End If
- i += 1
- End While
- If System.IO.File.Exists(FileName) = True Then
- Dim file2 As String() = IO.File.ReadAllLines(FileName)
- For a = 0 To file2.GetUpperBound(0)
- If file2(a).Length > Key.Length Then
- If file2(a).Substring(0, Key.Length) & ":" <> Key & ":" Then
- FileData = FileData & file2(a) & vbNewLine
- End If
- Else
- FileData = FileData & file2(a) & vbNewLine
- End If
- Next
- End If
- Dim file As New StreamWriter(FileName)
- file.Write(FileData & Key & ":" & Data)
- file.Close()
- End Sub
- Public Function Read(ByVal FileName As String, ByVal Key As String) As String
- Dim a As Integer
- If System.IO.File.Exists(FileName) = True Then
- Dim file As String() = IO.File.ReadAllLines(FileName)
- For a = 0 To file.GetUpperBound(0)
- If file(a).Length > Key.Length Then
- If file(a).Substring(0, Key.Length) & ":" = Key & ":" Then Return file(a).Substring(Key.Length + 1, file(a).Length - (Key.Length + 1))
- End If
- Next
- End If
- Return Nothing
- End Function
- Public Function KeyExists(ByVal FileName As String, ByVal Key As String) As Boolean
- Dim a As Integer
- If System.IO.File.Exists(FileName) = True Then
- Dim file As String() = IO.File.ReadAllLines(FileName)
- For a = 0 To file.GetUpperBound(0)
- If file(a).Length > Key.Length Then
- If file(a).Substring(0, Key.Length) & ":" = Key & ":" Then Return True
- End If
- Next
- End If
- Return False
- End Function
- End Module
- 'Reference excess
- 'dir = FileName.Substring(x, FileName.IndexOf("/", i) - x)
- 'file = FileName.Substring(x, FileName.Length - x)
Add Comment
Please, Sign In to add comment