### Welcome to SPN

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

# Delete multiple files from a folder using an Access Database

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

Tags:
1. ### 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

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.

#1

2. ### 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
>
> 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