String Modification

That’s what I did – and it works. I posed the question, though, because I’m new to Xojo and it has a lot of features (that seem to get renamed or changed at the drop of a hat) that I don’t know.

MVPs or not MVPs they are just trying to help and yet you complain? Hard to please people

Another way to do it:

Var fname As String = "log-20220513.txt"
Var daysInterval As New DateInterval(0, 0, 14)
Var minDate As Datetime = DateTime.Now - daysInterval
Var minFile As String = "log-" + minDate.SQLDate.ReplaceAll("-","") + ".txt"
If fname < minFile Then
  //discard file
  //keep file
End If

I think with this code you only need to create minFile once and test all files with that. With your code, you need to create ‘target’ and ‘dif’ for each file.

1 Like

You’ll also be wanting to go through the entire directory and ignore files that don’t conform to that filename format (there may be other files there or hidden ones). So something like:

dirh = new FolderItem ("/path/to/your/folder", FolderItem.PathModes.Native)
if  (dirh=Nil) then
  // Report error
end if

dircount = dirh.Count - 1

for  i = 0 to dircount
  nextfile = dirh.ChildAt (i)
  if  (nextfile=Nil)  then Continue
  name = nextfile.Name                                                      // Look through all items in this folder
  if  (name.BeginsWith(".")=True)  then Continue                            // Skip any starting with .
  if  (name.BeginsWith("log-")=False)  then Continue                        // Skip any file to be ignored

  // Process your file here


I do. I iterate through the files and if a file exists, its name is passed to a function called IsLogFile() that returns a Boolean.

If (s.Length = 16) And s.BeginsWith("log-") And s.EndsWith(".txt") Then
  Return True
  Return False
End If

I did this as a function because there are two areas of my little utility that need to know if a file in application’s folder is a log file or not.

Thank you for the suggestion. I will give it a try.