Im trying to grab information from files in a folder and create a file with all the information but im having trouble getting the write info =/ This is my current code where i have my problem:
vb.net Code:
Option Strict On
Option Explicit On
Option Infer Off
Imports ConsoleApplication1.Crc_Class
Imports System.IO
Module Module1
Dim PatchFile As FileStream = New FileStream("C:\Users\Home\Desktop\Patch.xml", FileMode.Create, FileAccess.Write)
Dim Writer As New StreamWriter(PatchFile)
Dim Crc_Class As New CRC32
Dim Raw_Crc_Integer As Integer
Dim looped As Integer = 0
Sub Main()
Try
input:
Console.WriteLine("Input directory...")
Dim workdir As String = Console.ReadLine
If Not System.IO.Directory.Exists(workdir) Then
Console.WriteLine("Incorrect input: Directory doesnt exist.")
GoTo input
End If
Writer.Write("<XML>" & vbCrLf & "<PATCHINFO>" & vbCrLf)
Dim foundfiles As String() = IO.Directory.GetFiles(workdir)
Dim amountoffoundfiles As Integer = IO.Directory.GetFiles(workdir).Count
For Each FullPath As String In foundfiles
Dim FileStream As New IO.FileStream(FullPath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192I)
Raw_Crc_Integer = Crc_Class.GetCrc32(FileStream)
Writer.WriteLine(" <PATCHNODE file=" & Path.GetFileName(FullPath) & ">" & vbCrLf & _
" <CRC>" & Raw_Crc_Integer.ToString & "</CRC>" & vbCrLf & _
" <SERVERLINK>" & (IO.Path.GetDirectoryName(FullPath).Replace(Path.GetDirectoryName(IO.Path.GetDirectoryName(FullPath)), String.Empty)) & "\" & IO.Path.GetFileName(FullPath) & "</SERVERLINK>" & vbCrLf & " </PATCHNODE>")
looped += 1
Console.WriteLine("Writing: (" & looped.ToString & "/" & amountoffoundfiles.ToString & ")")
Next
Writer.WriteLine("</PATCHINFO>" & vbCrLf & "</XML>")
Writer.Close()
Catch ex As Exception
Console.WriteLine(ex.Message & vbCrLf & "Press any button to continue...")
Console.ReadLine()
GoTo input
End Try
End Sub
End Module
Im trying to get it to loop once and write all the files (including files in other directories in the main folder but i cant get the code correct, any help?)