Click here to Skip to main content
16,014,860 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: DataSet auto increment problem Pin
Quecumber25629-May-07 9:31
Quecumber25629-May-07 9:31 
GeneralRe: DataSet auto increment problem Pin
kubben29-May-07 14:47
kubben29-May-07 14:47 
Questioninsert listbox items into database Pin
jds120729-May-07 7:49
jds120729-May-07 7:49 
AnswerRe: insert listbox items into database Pin
Dave Sexton29-May-07 8:05
Dave Sexton29-May-07 8:05 
GeneralRe: insert listbox items into database Pin
jds120729-May-07 8:30
jds120729-May-07 8:30 
GeneralRe: insert listbox items into database Pin
Dave Sexton29-May-07 22:04
Dave Sexton29-May-07 22:04 
Questionhow to show video properties Pin
somchoto29-May-07 7:43
somchoto29-May-07 7:43 
Questionsearch for files Pin
jds120729-May-07 4:20
jds120729-May-07 4:20 
I have a program that will allow me to enter a folder path into a textbox and file extension into a textbox. Once the path and the extension are typed in, click the search button and the files within the folder specified and the extension entered will be added to listbox1. Also, I have a access table named tblExclude that contains excluded files. In the program, if the folder path in tblExclude is equal to the path entered into the textbox then the filename will be added to listbox2.

For example:
'If the following 2 files are in tblExclude:
ExcludeFilePath: C:WINDOWS\Media
ExcludeFileName: recycle.wav

ExcludeFilePath: C:WINDOWS\Media
ExcludeFileName: recycle2.wav

'Then when you enter your path in Textbox1:
C:WINDOWS\Media

both of the following files that are in tblExclude are added to listbox 2:
recycle.wav
recycle2.wav

But I have a problem. I am only searching for excluded files by the folder path. I need to be able to search for excluded files by the path and extension. Because right now, if I enter folder path "C:\WINDOWS\Media" into textbox1 and click the search button the files in tblExclude will be displayed in listbox 2 without entering the extension in textbox. So I need to be able to search for files in tblExclude by path and ext.

Here is my code:

Dim dt As DataTable<br />
<br />
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click<br />
        'Get the entered file paths and patterns<br />
        Dim enteredFilePaths As String() = TextBox1.Text.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries)<br />
        Dim patterns As String() = TextBox2.Text.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries)<br />
<br />
        'Declare a string array to store the file paths that are not found in the database<br />
        Dim filePaths() As String = Nothing<br />
        <br />
        Dim dv As DataView = dt.DefaultView<br />
        dv.Sort = "ExcludePath ASC"<br />
<br />
        For Each path As String In enteredFilePaths<br />
            'Check to make sure the file path does not have "\" as it's last character.<br />
            If path.LastIndexOf("\") = path.Length - 1 Then<br />
                path = path.Substring(0, path.Length - 1)<br />
            End If<br />
<br />
            Dim rows As DataRowView() = dv.FindRows(path)<br />
            If rows.Length > 0 Then<br />
                For Each row As DataRowView In rows<br />
                    'It was found in the database, display it in the listbox.<br />
                    Me.ListBox2.Items.Add(row.Item("ExcludeFileName"))<br />
                Next<br />
            Else<br />
                'It was not found in the database<br />
                Dim i2 As Integer = 0<br />
                If Not filePaths Is Nothing Then<br />
                    i2 = UBound(filePaths) + 1<br />
                End If<br />
<br />
                'Resize the array<br />
                ReDim filePaths(i2)<br />
<br />
                'Add the path to the array<br />
                filePaths(i2) = path<br />
            End If<br />
        Next<br />
        GetDirectoryContents(enteredFilePaths, patterns)<br />
<br />
    Private Sub GetDirectoryContents(ByVal dirs() As String, ByVal patterns() As String)<br />
        'Declare variable.<br />
        Dim dDir As DirectoryInfo<br />
<br />
        'Search directory for files and add to the listbox.<br />
        For Each sDir As String In dirs<br />
            If Not Directory.Exists(sDir) Then Continue For<br />
            dDir = New DirectoryInfo(sDir)<br />
            For Each ext As String In patterns<br />
                For Each fi As FileInfo In dDir.GetFileSystemInfos("*." & ext)<br />
                    ListBox1.Items.Add(fi.Name)<br />
                Next<br />
            Next<br />
        Next<br />
    End Sub<br />
<br />
   Private Sub LoadData()<br />
        'Create a datatable to store data<br />
<br />
        dt = New DataTable("tblExclude")<br />
        Dim colExFileID As New DataColumn("ExcludeID")<br />
        Dim colExFilePath As New DataColumn("ExcludePath")<br />
        Dim colExFileName As New DataColumn("ExcludeFileName")<br />
        DataGridView1.DataSource = dt<br />
<br />
        dt.Columns.AddRange(New DataColumn() {colExFileID, colExFilePath, colExFileName})<br />
<br />
        Dim myConnString As String = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\File.mdb"<br />
        Dim myConnection As New OleDbConnection(myConnString)<br />
        myConnection.Open()<br />
        Dim strSQL As String = "SELECT * FROM tblExclude"<br />
<br />
        Dim dAdapter As New OleDbDataAdapter()<br />
        dAdapter.SelectCommand = New OleDbCommand(strSQL, myConnection)<br />
<br />
        'Retrieve the data from the database and load the DataTable with it<br />
        dAdapter.Fill(dt)<br />
<br />
        myConnection.Close()<br />
<br />
    End Sub<br />
<br />
    Private Sub SearchFileForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
        LoadData()<br />
<br />
    End Sub


Any ideas?


jds1207
QuestionCallByName Pin
advansis29-May-07 4:11
advansis29-May-07 4:11 
AnswerRe: CallByName Pin
Dave Kreskowiak29-May-07 6:56
mveDave Kreskowiak29-May-07 6:56 
AnswerRe: CallByName Pin
Ian Shlasko29-May-07 11:06
Ian Shlasko29-May-07 11:06 
GeneralRe: CallByName Pin
Dave Kreskowiak29-May-07 13:23
mveDave Kreskowiak29-May-07 13:23 
QuestionWhat is the conversion between postscript points to em? Pin
Marcus J. Smith29-May-07 2:00
professionalMarcus J. Smith29-May-07 2:00 
AnswerRe: What is the conversion between postscript points to em? Pin
advansis29-May-07 4:18
advansis29-May-07 4:18 
QuestionThis field cannot be summarized Pin
Rm_alamami29-May-07 1:24
Rm_alamami29-May-07 1:24 
AnswerRe: This field cannot be summarized Pin
Rupesh Kumar Swami29-May-07 1:45
Rupesh Kumar Swami29-May-07 1:45 
QuestionHow to Set Media Format when Ripping CD in Windows media player 11 SDK Pin
Juvil John29-May-07 1:19
Juvil John29-May-07 1:19 
Questionsingle quotes in vb.net Pin
Sonia Gupta29-May-07 1:11
Sonia Gupta29-May-07 1:11 
AnswerRe: single quotes in vb.net Pin
Ali 11029-May-07 1:19
Ali 11029-May-07 1:19 
GeneralRe: single quotes in vb.net Pin
Sonia Gupta29-May-07 2:01
Sonia Gupta29-May-07 2:01 
GeneralRe: single quotes in vb.net Pin
Colin Angus Mackay29-May-07 3:11
Colin Angus Mackay29-May-07 3:11 
GeneralRe: single quotes in vb.net Pin
Colin Angus Mackay29-May-07 3:12
Colin Angus Mackay29-May-07 3:12 
AnswerRe: single quotes in vb.net Pin
Rupesh Kumar Swami29-May-07 1:22
Rupesh Kumar Swami29-May-07 1:22 
GeneralRe: single quotes in vb.net Pin
Sonia Gupta29-May-07 2:01
Sonia Gupta29-May-07 2:01 
GeneralRe: single quotes in vb.net Pin
Colin Angus Mackay29-May-07 3:14
Colin Angus Mackay29-May-07 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.