Solved

Read file in order

Posted on 2007-11-15
1
164 Views
Last Modified: 2010-04-23
There are, for example, three file name "A.txt" "B.txt" "C.txt". Is it possible to reach these files in order. A, then B then C at a time.




For each myfile as fileinfo in mydir.getfiles("*.txt")

   Readmyfile...etc



Next
0
Comment
Question by:VBdotnet2005
1 Comment
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 20290965
Here's how you can do it:

   Private Sub SortFiles()

        Dim mydir As String = "C:\temp"

        Dim list As New List(Of System.IO.FileInfo)
        list.AddRange(New IO.DirectoryInfo(mydir).GetFiles("*.txt"))
        list.Sort(AddressOf Sort)

        For Each myfile As System.IO.FileInfo In list
            Debug.WriteLine(myfile.Name)

        Next

    End Sub

    Private Function Sort(ByVal x As IO.FileInfo, ByVal y As IO.FileInfo) As Integer

        Return x.Name.CompareTo(y.Name)

    End Function

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Close tabpage of custom control 9 35
Help with AsEnumerable(), LINQ 4 40
Import a txt file into a DataGridView and TextBox 20 38
VB.NET 2008 Publish Error 2 27
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question