Results 1 to 2 of 2

Thread: List files in a directory + write the result in a text files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    94

    List files in a directory + write the result in a text files

    Dear all,

    I am trying to create a program which will read the files that exist in a directory, and then write in a text file the specific information (full file name, date created)

    i have found several code in the site but i cant make it work, the machine i am running the code is XP and i am using VB2008.

    The code i have found is the following:

    Imports System.IO
    Imports System.String


    Public Class Class1

    Dim di As New IO.DirectoryInfo("C:\temp")
    Dim Directory1 As IO.FileInfo() = di.GetFiles()
    Dim File As IO.FileInfo
    For Each File In Directory1
    My.Computer.FileSystem.WriteAllText("C:\Hello.txt", File.FullName & vbCrLf, True)
    Next


    End Class


    DOes this code create a file Hello.txt with the information that i need???


    when i run the code which i dont know if it is the correct one i get the following errors:
    1. Sub main was not found in "Project Name"
    2. Statement cannot appear outside of a method body (it is for the line which starts with "For Each.........")
    3.Declaration expected (for the word "My.")
    4. sntax error (for the word "Next"


    Thanks in advance for your help,

    Best Regards

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,421

    Re: List files in a directory + write the result in a text files

    your code is outside of a sub or function.

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