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!

I am attempting to delete log files

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
US
I am attempting to delete log files that are older then a specified dat in Visual Basic. I know I can do this doing something like:

Dim DirName As String
Dim FileDate As Date

DirName = "C:\RDS\rdsbox\boxdata\Temp\Backup"

ChDir DirName
FileName = Dir$("*.*", ATTR_NORMAL)
Do While FileName <> &quot;&quot;
FileDate = FileDateTime(FileName)

If Now - FileDate > 10 Then
Kill FileName
End If

FileName = Dir$
Loop

However Dir$ doesn't go to the next file. Is there a way to either slect files that are older then a specified date or simply have Dir go onto the next file?
 
What you're doing should work fine, but ChDir won't change the default drive. If you're on the D: drive and run this, then Dir$ is going to go through the files in the current directory of the D: drive, not the C: drive.

I would recommend, either doing a ChDrive &quot;C&quot; to move to that drive, or to not change the drive/directory and just put the path on the front of the FileName.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top