Solved

Compare list of numbers against directory list of file names

Posted on 2008-06-16
3
193 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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