Solved

Compare list of numbers against directory list of file names

Posted on 2008-06-16
3
184 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now