Solved

Compare list of numbers against directory list of file names

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

705 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