Solved

MS Access Application.FileSearch

Posted on 2011-03-22
4
424 Views
Last Modified: 2013-11-27
After searching I found the problem is that 07 no longer supports the .FileSearch function (which is stupid IMO).  Anyway, I have code that worked in 03.  It searches for .log files in a directory and if there are more than 10 files present, it deleted the oldest one.  What do I need to use in 07 to do this?

Here is the code that worked in 03.

Thank you!

Sub DeleteOldestFile()
'maintains the number of log files to a max of 10.  Deletes the oldest file.
    Dim strFilePath As String

    strFilePath = GetDBPath
   
    With Application.FileSearch
       .NewSearch
       .LookIn = strFilePath
       .Filename = "*.log"
       .Execute
       If .FoundFiles.Count >= MAX_LOG_COUNT Then
            Kill .FoundFiles(1)
       End If
    End With
   
End Sub

Open in new window

0
Comment
Question by:AronMcD
  • 2
  • 2
4 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
you can try the File scripting, needs reference to Microsoft scripting runtime

codes goes something like this

Dim fso As Scripting.FileSystemObject
Dim srcFolder As Scripting.Folder
Dim fileItem As Scripting.File
Dim strFilePath As String

    strFilePath = GetDBPath

Set fso = New Scripting.FileSystemObject
Set srcFolder = fso.GetFolder(strFilePath)

    For Each fileItem In srcFolder.Files
        If Right(fileItem, 4) = ".log" Then
        Debug.Print fileItem.Name, fileItem.DateCreated
        End If
    Next
    

Open in new window

0
 

Author Comment

by:AronMcD
Comment Utility
capricorn,
Using fileItem.Delete deletes all files with the .log extension.  How do I delete just the oldest file?  

Thanks for the help.

0
 

Author Comment

by:AronMcD
Comment Utility
capricorn,
I got it to work using:

Kill strFilePath & fileItem.Name

Seems to work fine.....unless you know of a better way.

Thanks for the help.   I appreciate it.  
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
sorry, just got back from a meeting. glad you got it working..
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now