Attribute VB_Name = "fileaux"
Option Explicit

Public Function append_loosely$(FN$, TX$)

Dim handler%

handler = FreeFile
If TX = "" Or FN = "" Then Exit Function

On Error GoTo open_error
  
Open FN For Append Shared As handler   ' shared?
  
  On Error GoTo write_error
  Print #handler, TX;    ' semicolumn is vital here ...
  Close #handler

Exit Function

write_error:
  append_loosely = "Exception when writing a file `" & _
                   FN & "` in `write_f` module"
  Exit Function

open_error:
  append_loosely = "Exception when opening a file `" & _
                   FN & "` in `write_f` module"
Exit Function

End Function

'EXCE Free
'
Function write_loosely$(file_name$, file_text$)
Dim handler%

handler = FreeFile
If file_text = "" Or file_name = "" Then Exit Function

On Error GoTo open_error
Open file_name For Output Access Write Shared As handler
   
  On Error GoTo write_error
  Print #handler, file_text;    ' semicolumn is vital here ...
  Close #handler

Exit Function

write_error:
  write_loosely = "Exception when writing a file `" & _
                  file_name & "` in `write_f` module"
  Exit Function

open_error:
write_loosely = "Exception when opening a file `" & _
                file_name & "` in `write_f` module"
Exit Function

End Function




'EXCEP  Free
'DESCR  Renders file name without path.
'
Function get_short_name(full_file_name$)
   Dim i%
   i = instrrev(full_file_name, "\")
   If i = 0 Then i = instrrev(full_file_name, ":")
   If i <> 0 Then
      get_short_name = Mid(full_file_name, i + 1)
   Else
      get_short_name = full_file_name
   End If
End Function


'EXCEP          Free
'OUTPUT         Returns selected file name or "" if cancelled
'DEPENDENCIES   None
'
'
Public Function SelectFileForOpening$( _
       FileNameToStart$, _
       FilterToStart$, _
       Common_Dialog As CommonDialog, Exception$, DTitle$)

SelectFileForOpening = ""
Exception = ""
With Common_Dialog
        .Filter = FilterToStart
        .FileName = FileNameToStart
        .DialogTitle = DTitle
        .CancelError = True
        On Error Resume Next
        .ShowOpen
        If Err.Number > 0 Then
           If Err.Number = cdlCancel Then
              Err.Clear
              Exit Function
           Else
              GoTo he
           End If
        End If
        On Error GoTo he
        SelectFileForOpening = .FileName
End With
Exit Function

he: Exception = Err.Description & vbCrLf & _
                "When selecting file for opening."
    Exit Function
        
End Function

' COMMENTED because of rl ...
'
' deletes all files satisfying filePattern in folder_path which time stamp is more
' than seconds from Now
' displays process ...
' requires output stream rl to display ...
'Sub delete_all_files_before_displays(seconds%, folder_path$, filePattern$)
'   Dim f$, f_full$, full_prefix$, ws$
'   Dim w_date As Date, w_time$, w_day$
'   Dim w_difference&
'
'   On Error GoTo he
'
'   full_prefix = folder_path
'   If Right(folder_path, 1) <> "\" Then full_prefix = folder_path & "\"
'
'   f = Dir(full_prefix & filePattern)
'   If Len(f) = 0 Then Exit Sub
'
'   Do While f <> ""
'
'        f_full = full_prefix & f
'        w_date = FileDateTime(f_full)
'        w_time = Format(w_date, "hhmmss")
'        w_day = Format(w_date, "YYYYMMDD")
'        ' rcon f & Chr(9) & FileDateTime(f) ' does not work
'        rl f & Chr(9) & " date(YYYYMMDD)=" & w_date
'        rl f & Chr(9) & " day=" & w_day & Chr(9) & " time(hhmmss)=" & w_time
'        w_difference = DateDiff("s", w_date, Now)
'        If w_difference > seconds Then
'           Kill f_full
'           rl f & " is deleted ... because difference = " & w_difference
'        End If
'        f = Dir()
'   Loop
'   Exit Sub
'he: MsgBox Err.description
'End Sub




' deletes all files satisfying filePattern in folder_path
' which time stamp is more
' than seconds from Now ...
Sub delete_all_files_before(seconds%, folder_path$, filePattern$)
   Dim f$, f_full$, full_prefix$
   
   full_prefix = folder_path
   If Right(folder_path, 1) <> "\" Then full_prefix = folder_path & "\"
   
   f = Dir(full_prefix & filePattern)
   If Len(f) = 0 Then Exit Sub
   
   Do While f <> ""
        'rl f & " ... "
        f_full = full_prefix & f
        If DateDiff("s", FileDateTime(f_full), Now) > seconds Then
           Kill f_full
           'Log.Puts LOGAREA_SERVER, LOG_APPMSG, "file " & f & " is older than " & seconds & " seconds - deleted ... "
        End If
        f = Dir()
   Loop
End Sub