borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Referencing ADO Data)Next Topic (how to maintain unique ID's in a database) New Topic New Poll Post Reply
AndreaVB Forum : Database : Importing File Names Into DB
Poster Message
Shady
Level: VB Guru


Registered: 08-07-2002
Posts: 305

icon Importing File Names Into DB

I need to read a list of files in a specific directory, then determine which of the files have already been included in my database and just add the newest files.

E.G.

I have a directory called C:CarDBImages

periodically I will add files to this directory, but the files will be viewed through a VB GUI, instead of having to manually enter the name of every image, I need code that will read the files in the directory and then determine which file names have already been included in the database (Access 97) and only add the new ones!!

Any Hints, Tips etc appreciated

Regards

Shady

____________________________
I don't wanna die... but I ain't keen on livin' either

20-06-2003 at 10:22 AM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: Importing File Names Into DB

Hi Shady

To get the list of files , use the file list box.

Then to stop duplicates getting into your db set the field in access to "No duplicates" (thats in the index setings) then before you do the insert do an "on error resume next"

Thats one way of doing it


[Edited by steve_w on 20-06-2003 at 10:34 AM GMT]

20-06-2003 at 10:31 AM
View Profile Send Email to User Show All Posts | Quote Reply
Shady
Level: VB Guru


Registered: 08-07-2002
Posts: 305
icon Re: Importing File Names Into DB

OK so we have the beginning of a good idea here.

Now my area of expertise is controlling databases with code, I have not used a file list box since VB3, which is a while back, so I'm presuming we're using a FOR NEXT loop to systematically pick up the first filename, then cycle through the rest:-

For x = 1 to NumberOfImages

on error resume next

ImageDB.Recorset.Addnew
ImageDB.Recordset("FileName")=FileList.Index(x)
ImageDB.Recordset.Update

Next x

So help me out here how close (or far away) am I??

And how do I count how many files are in a directory?

  

Shady

[Edited by Shady on 20-06-2003 at 10:42 AM GMT]

[Edited by Shady on 20-06-2003 at 10:42 AM GMT]

____________________________
I don't wanna die... but I ain't keen on livin' either

20-06-2003 at 10:40 AM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: Importing File Names Into DB

Try this I have changed so that instead of doing an on error resume next try and trap any other errors.


Dim i As Integer

    File1.Path = "c:"
    For i = 0 To File1.ListCount - 1
    

on error goto Err_Check

        ImageDB.Recorset.Addnew
        ImageDB.Recordset("FileName")=File1.list(i)
        ImageDB.Recordset.Update

Err_Check:

        if err.number <> "what ever the error code is for duplicates" then
            msgbox err.description
        endif

    Next i



How about that one!!

[Edited by steve_w on 20-06-2003 at 11:02 AM GMT]

20-06-2003 at 11:00 AM
View Profile Send Email to User Show All Posts | Quote Reply
Shady
Level: VB Guru


Registered: 08-07-2002
Posts: 305
icon Re: Importing File Names Into DB

Thanks very much Steve

Much appreciated, as soon as I get stuck again I'll let you know
  

Shady

____________________________
I don't wanna die... but I ain't keen on livin' either

20-06-2003 at 11:59 AM
View Profile Send Email to User Show All Posts | Quote Reply
Shady
Level: VB Guru


Registered: 08-07-2002
Posts: 305
icon Re: Importing File Names Into DB

Just had a thought (it hurt too!)

instead of placing the filenames into a database and having the program update the content every time, I can use the file list box to select the images direct from the hard drive.

So 2 questions:-

1. What is the code for passing the selected file to the PictureBox

i.e. PictureBox1.Pic=File1.CurrentSelection

2. Is it possible to restrict the files displayed in the File box using Wildcards

i.e. File1.FilePattern = "C:ImagesAB12DEF*.*"

Your input would be most helpful.

Regards

Shady

____________________________
I don't wanna die... but I ain't keen on livin' either

20-06-2003 at 12:20 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: Importing File Names Into DB

You want


Private Sub File1_Click()

    Picture1.Picture = LoadPicture(File1.Path & "" & File1.FileName)

End Sub


and to restrict the list
        File1.Path = "c:"
        File1.Pattern = "*.bmp;*.jpg" 'etc






20-06-2003 at 12:42 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : Importing File Names Into DB
Previous Topic (Referencing ADO Data)Next Topic (how to maintain unique ID's in a database) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder