?
Solved

Compare list of numbers against directory list of file names

Posted on 2008-06-16
3
Medium Priority
?
199 Views
Last Modified: 2013-12-16
This is a VB.NET/C# progamming question.
Given a list of numbers from a table column and a network folder directory list of file names, we need to do the following:
1) Code to retrieve and store the list of numbers from the table column.
2) Code to retrive and store network folder directory list of file names.
3) Code to compare list of numbers against directory list of file names and place in a list numbers that are not contained in any file name. For example:  123456 is contained in 12345.txt
Thanks for any help.
0
Comment
Question by:ksfok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 2000 total points
ID: 21832333
Well

There many ways to address this , also more effecient as show below but it should get you started



Imports System.Data


    Dim con As New OleDb.OleDbConnection
    Dim ds As DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String


     'Get some file names from a database
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Test.mdb"
        sql = "SELECT * FROM FileNames"
        con.Open()

        da = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet("FileNames")
        da.Fill(ds, "FileNames")

        con.Close()

       CompareFiles()

    End Sub



   Private Sub CompareFiles()

      'Select a folder from a drive

        Dim mydir As String = "C:\temp"

       'Add the content to a list

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

      'Do a compare

        For Each myfile As System.IO.FileInfo In list
            Debug.WriteLine(myfile.Name)                                        'table attribute
            Dim rows() As DataRow = ds.Tables("FileNames").Select("fNames=' & myfile.Name& "'")

            'Show the no.matches
            MessageBox.Show(rows.Length)
        Next

    End Sub


hope this helps a bit

vbturbo
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

801 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