Solved

Compare list of numbers against directory list of file names

Posted on 2008-06-16
3
190 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
3 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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