Open File in background

I would like to open a file, update a field, save and close all in the back ground with out any dialogs. Can anyone point me in the right direction.

Hi Larry,

Knowing what kind of file (text/binary, how it is created, …) would make it much easier to help you.

Julen

You don’t have to create a FolderItem by using a Open dialog; if you know the path (that is, location on your drive), either absolute or relative to something you can get (e.g. SpecialFolder.Desktop) then by using FolderItem.Child() or FolderItem.Parent, then use that FolderItem, open the file as a Binary Stream, and do your work, and close.

But if you have to find your FolderItem; that is, you don’t ever know exactly where it is, or you want your user to find it, a Open dialog is usually necessary.

The other idea, that is if your file has a unique name, you don’t know where it is, and you’re using Mac, is to use the find function in a shell. This is the custom function I use (forgive the imperfections):

[code]Function FindViaShell(FileName As String, DirPath As FolderItem) As FolderItem

Dim s As Shell
Dim Msg As String
Dim f As FolderItem
Dim ResultPath As String

If DirPath <> Nil then

s = New Shell
s.Mode = 0

Msg = "find " + DirPath.ShellPath + " -name " + Chr(34) + FileName + Chr(34) + " -print"

s.Execute Msg

If s.errorCode = 0 then
  If s.Result = "" Then
    return Nil
  Else
    if Asc(Right(s.Result, 1)) < 32 Then
      ResultPath = Left(s.Result, Len(s.Result) - 1)
    Else
      break
      ResultPath = s.Result
    End If
    f = GetFolderItemRCS(ResultPath)
    return f
  End If
else
  break
  WriteLogFile("Error code: " + StrNum(s.ErrorCode))
  return Nil
End If

Else

return Nil

End If

End Function[/code]