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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a way to delete a file? i 1

Status
Not open for further replies.

drctx

IS-IT--Management
May 20, 2003
226
US
is there a way to delete a file? i have a database that repairs and compacts a list of databases in a table and creates a new db as dbname_C.mdb that's been compacted, then i want to delete the non compacted version and the rename the dbname_C.mdb file. everything works execpt the delete.

Private Sub Command2_Click()

Dim RS As DAO.Recordset, DB As DAO.Database
Dim NewDBName As String, DBName As String
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames")
On Error Resume Next
RS.MoveFirst
Do Until RS.EOF
DBName = RS("DBFolder") & "\" & RS("DBName")
' Create a new name for the compacted database.
' This example uses the old name plus the current date.
NewDBName = Left(DBName, Len(DBName) - 4)
NewDBName = NewDBName & "_C.mdb"
DBEngine.CompactDatabase DBName, NewDBName
RS.MoveNext
Loop

' delete databases not ending in _C
Do Until RS.EOF
DBName = RS("DBFolder") & "\" & RS("DBName")

'***************************************
'delete files
'Delete DBName
'Delete File code here

'***************************************

RS.MoveNext
Loop

' rename compacted databases back to original name
Do Until RS.EOF
DBName = RS("DBFolder") & "\" & RS("DBName")
' Create a new name for the compacted database.
' This example uses the old name plus the current date.
NewDBName = Left(DBName, Len(DBName) - 4)
NewDBName = NewDBName & "_C.mdb"
Name NewDBName As DBName
RS.MoveNext
Loop

RS.Close
End Sub
 
Sure just use the Kill command followed by the path of the file:

Kill "C:\YourFileName.txt"



Regards,
gkprogrammer
 
that works great, thanks! also noticed that i needed RS.MoveFirst before each loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top