Results 1 to 4 of 4

Thread: [RESOLVED] [2008] Getting and writing information to a file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Resolved [RESOLVED] [2008] Getting and writing information to a file

    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:
    1. Option Strict On
    2. Option Explicit On
    3. Option Infer Off
    4. Imports ConsoleApplication1.Crc_Class
    5. Imports System.IO
    6.  
    7. Module Module1
    8.     Dim PatchFile As FileStream = New FileStream("C:\Users\Home\Desktop\Patch.xml", FileMode.Create, FileAccess.Write)
    9.     Dim Writer As New StreamWriter(PatchFile)
    10.     Dim Crc_Class As New CRC32
    11.     Dim Raw_Crc_Integer As Integer
    12.     Dim looped As Integer = 0
    13.     Sub Main()
    14.         Try
    15. input:
    16.             Console.WriteLine("Input directory...")
    17.             Dim workdir As String = Console.ReadLine
    18.             If Not System.IO.Directory.Exists(workdir) Then
    19.                 Console.WriteLine("Incorrect input: Directory doesnt exist.")
    20.                 GoTo input
    21.             End If
    22.             Writer.Write("<XML>" & vbCrLf & "<PATCHINFO>" & vbCrLf)
    23.             Dim foundfiles As String() = IO.Directory.GetFiles(workdir)
    24.             Dim amountoffoundfiles As Integer = IO.Directory.GetFiles(workdir).Count
    25.             For Each FullPath As String In foundfiles
    26.                 Dim FileStream As New IO.FileStream(FullPath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192I)
    27.                 Raw_Crc_Integer = Crc_Class.GetCrc32(FileStream)
    28.                 Writer.WriteLine("  <PATCHNODE file=" & Path.GetFileName(FullPath) & ">" & vbCrLf & _
    29.                                  "      <CRC>" & Raw_Crc_Integer.ToString & "</CRC>" & vbCrLf & _
    30.                                  "      <SERVERLINK>" & (IO.Path.GetDirectoryName(FullPath).Replace(Path.GetDirectoryName(IO.Path.GetDirectoryName(FullPath)), String.Empty)) & "\" & IO.Path.GetFileName(FullPath) & "</SERVERLINK>" & vbCrLf & "  </PATCHNODE>")
    31.                 looped += 1
    32.                 Console.WriteLine("Writing: (" & looped.ToString & "/" & amountoffoundfiles.ToString & ")")
    33.             Next
    34.             Writer.WriteLine("</PATCHINFO>" & vbCrLf & "</XML>")
    35.             Writer.Close()
    36.         Catch ex As Exception
    37.             Console.WriteLine(ex.Message & vbCrLf & "Press any button to continue...")
    38.             Console.ReadLine()
    39.             GoTo input
    40.         End Try
    41.     End Sub
    42.  
    43. 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?)
    Last edited by youngbucks; Dec 25th, 2008 at 05:39 AM.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: [2008] Getting and writing information to a file

    vb.net Code:
    1. Writer.WriteLine("<PATCHNODE file=""" & Path.GetFileName(FullPath) & """>"
    or:
    vb.net Code:
    1. Writer.WriteLine("<PATCHNODE file=" & ControlChars.Quote & Path.GetFileName(FullPath) & ControlChars.Quote & ">"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: [RESOLVED] [2008] Getting and writing information to a file

    Thanks that was what i was looking for, i just need help with the for statement now.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: [RESOLVED] [2008] Getting and writing information to a file

    To loop through all the files in a folder:
    vb.net Code:
    1. For Each filePath As String In IO.Directory.GetFiles("folder path here")
    2.     'Use filePath here.
    3. Next
    To loop through all the folders in a folder:
    vb.net Code:
    1. For Each folderPath As String In IO.Directory.GetDirectories("folder path here")
    2.     'Use folderPath here.
    3. Next
    You can nest those two to perform a recursive search.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width