Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

Delete multiple files from a folder using an Access Database

Discussion in 'Information Technology' started by dlow123@gmail.com, Jul 28, 2006.

  1. dlow123@gmail.com

    dlow123@gmail.com
    Expand Collapse
    Guest

    Good Morning All,

    I am not sure if I am posting this in the right place, but please bear
    with me.

    I am trying to run a db query to quickly populate a database with
    filenames from a folder on my hard drive. Then in turn I would like to
    be able to delete files from the folder, based on my deletes in the
    database.

    I hope that this makes sense. I am currently using the following code
    in the Visual Basic editor to populate my table with the necessary
    data:

    Sub GetGameFiles()
    Dim strFile As String
    Dim strFolder As String
    Dim strSQL As String

    strFolder = "C:\path\to\thefile\iwantadded\tothisdb\"
    strFile = Dir(strFolder & "*.*")
    Do While Len(strFile) > 0
    strSQL = "INSERT INTO gamenames (gamefilename) " & _
    "VALUES (" & Chr$(34) & strFile & Chr$(34) & ")"
    CurrentDb.Execute strSQL, dbFailOnError
    strFile = Dir()
    Loop

    End Sub

    I am currently running Access 2003. I also thought about trying this
    with Excel 2003

    If anyone can offer assistance it would be greatly appreciated.

    Thank you.

    Devon L.
     
  2. Loading...


  3. Michael H

    Michael H
    Expand Collapse
    Guest

    Hi.

    Is there any other reason you are placing the filenames into a table first?
    Why not just delete the files within the Do While loop?

    Just replace this:
    strSQL = "INSERT INTO gamenames (gamefilename) " & _
    "VALUES (" & Chr$(34) & strFile & Chr$(34) & ")"
    CurrentDb.Execute strSQL, dbFailOnError

    With this:
    Kill strFolder & strFile

    Or, if you need the filenames in a table for some additional reason, just
    insert my line of code right before this one:
    strFile = Dir()

    -Michael



    "dlow123@gmail.com" wrote:

    > Good Morning All,
    >
    > I am not sure if I am posting this in the right place, but please bear
    > with me.
    >
    > I am trying to run a db query to quickly populate a database with
    > filenames from a folder on my hard drive. Then in turn I would like to
    > be able to delete files from the folder, based on my deletes in the
    > database.
    >
    > I hope that this makes sense. I am currently using the following code
    > in the Visual Basic editor to populate my table with the necessary
    > data:
    >
    > Sub GetGameFiles()
    > Dim strFile As String
    > Dim strFolder As String
    > Dim strSQL As String
    >
    > strFolder = "C:\path\to\thefile\iwantadded\tothisdb\"
    > strFile = Dir(strFolder & "*.*")
    > Do While Len(strFile) > 0
    > strSQL = "INSERT INTO gamenames (gamefilename) " & _
    > "VALUES (" & Chr$(34) & strFile & Chr$(34) & ")"
    > CurrentDb.Execute strSQL, dbFailOnError
    > strFile = Dir()
    > Loop
    >
    > End Sub
    >
    > I am currently running Access 2003. I also thought about trying this
    > with Excel 2003
    >
    > If anyone can offer assistance it would be greatly appreciated.
    >
    > Thank you.
    >
    > Devon L.
    >
    >
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page