Deleting files using VB and queries

B

brian

I have a VB app that searches 5 directories from the root.

For example:

Function PurgeJobFiles()
Dim db As Database, rs As Recordset
Const OMNIchrd_PATH = "N:\OMNIchrd\"

On Error Resume Next

Set db = DBEngine.Workspaces(0).Databases(0)
Set rs = db.OpenRecordset("qryDelete_Shop_File", DB_OPEN_DYNASET)
' Create dynaset.

rs.MoveFirst ' Move to first record.
If Err <> 0 Then
rs.Close ' Close recordset
On Error GoTo 0 ' Reset error processing
Exit Function ' Exit
End If

Do Until rs.EOF ' Loop until no matching records.
Kill OMNIchrd_PATH & rs!JOB_NO & "*.*" ' Delete OMNI
files.

rs.MoveNext ' Move to next record.
Loop ' End of loop.
MsgBox "Files have been deleted", vbOKOnly, "Deleted Files"
rs.Close ' Close recordset
On Error GoTo 0 ' Reset error processing

End Function

This deletes every record in the root directory that matches the
query. I have been given a new task to search directories with sub
directories within subdirectories. Is there a dynamic way of
searching through the root directory and hit all the sub directories?

Thanks
 
N

new.microsoft.com

sure - you might want to create a recursive function or process to traverse
the direcory sturcture. use the Scripting.FileSystemObject. in conjunction
with your query. It looks like you are storing a partial file name in the
db and using that to delete all files with that prefix. In additon to
Microsoft Scripting Runtime you might perfer looking into WBEM objects to
query the filesystem.

sorry I don't have any handy code samples for you but i've used both objects
to accomplish similar tasks.

Good Luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top