Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing file names

Status
Not open for further replies.

JoeCool32

Programmer
Sep 26, 2002
50
0
0
US
I know how to bring up the contents of a folder and, I know how to fill a listbox by using a SQL statement. I don't know how to combine the two.

Here's the challenge. I'm trying to read file names from a listbox (which were filled after reading from a SQL field) and compare each one of them with entries from a file folder using the GetFiles object. The objective is to fill the listbox w/ file names that exist only in the folder and weed out the names that match in the SQL table. Ideas, anyone? JJ [peace]

"Ignorance and prejudice and fear walk hand in hand" - Witch Hunt, by Rush
 
the DirectoryInfo.GetFiles Method () will return the list of files in a directory, once you've set the DirectoryInfo object.

Terry
 
I'm already using that.

My main problem is in the loop where it goes through the file names in the folder. It's supposed to check against the values brought from the SQL table one by one. When there's no match for a particulae file name it gets written to the listbox.

As it stands now, the listbox is getting duplicate file names instead of ones unique to the folder only.

Here's my VB code as it stands now:

Code:
Private Sub RevealFileNames()
    Dim filePath As String = "C:\Inetpub\[URL unfurl="true"]wwwroot\etc.,etc."[/URL]
    Dim dInfo As New DirectoryInfo(filePath)
    Dim fInfo As FileInfo() = dInfo.GetFiles
    Dim i As Integer = 0
    Dim strMemoName As String = ""
    Dim strMemoToAdd As String = ""
    For i = 0 To fInfo.Length - 1
        Dim objSQLMemoList As New SQLComponent()
        objSQLMemoList.strConnection = objConstants.DBConnectionString_Umove
        objSQLMemoList.strSQL = "SELECT * FROM umv_memoManagement"
        objSQLMemoList.ExecuteSqlStatementAndReturnResults()
            If objSQLMemoList.returnDataViewValue.Count > 0 Then
            Dim intCounter As Integer = 0
            If Trim(strMemoToAdd) = Trim(strMemoName) Then
                    intCounter += 1
            Else
                lstMemos.Items.Add(Trim(fInfo(i).Name.ToString))
            End If
            strMemoName = Trim(objSQLMemoList.returnDataViewValue(intCounter)("mgt_memoURL").ToString())
            strMemoToAdd = fInfo(i).Name.ToString
         End If
    Next
End Sub
JJ [peace]

"Ignorance and prejudice and fear walk hand in hand" - Witch Hunt, by Rush
 
Sorry about the first post. It would help if I read it more closely. You already figured out what I already posted.

It looks like your missing a for loop between the dim intcounter and if trim(strmemotoadd)... line and ending between the strmemoname = ... and the strmemotoadd =... lines.
 
You know, I had a For loop in there somewhere but it kept returning mutliple instances of every file name. I don't know if it was in the spot you suggested, but I'll try it at that point and let you know if it worked. JJ [peace]

"Ignorance and prejudice and fear walk hand in hand" - Witch Hunt, by Rush
 
Looking at it, it would create a hunge number of duplicate names that aren't in the sql.

Try a different approach of putting the file name from the directory info in a where clause in the sql and then determining if you get a result out of the sql query.

I always find the negative the harder way to program.

Terry
 
I'll try that next week. Right now with the For...Next loop my intCounter is returning server errors because its out of range. Thanks for your help. JJ [peace]

"Ignorance and prejudice and fear walk hand in hand" - Witch Hunt, by Rush
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top