Solved

MS Access Application.FileSearch

Posted on 2011-03-22
4
437 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 35189762
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
ID: 35190107
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
ID: 35190334
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35190534
sorry, just got back from a meeting. glad you got it working..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

808 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