Solved

MS Access Application.FileSearch

Posted on 2011-03-22
4
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

749 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