How can I open an arbitrary text file from a console application?

Hi Everyone,

I’m writing a console application where the user will specify a file to read as args(1). I know a little about TextInputStream for GUI applications but how do I open a file for use in the console? Also, how do I access a file out of the SpecialFolders hierarchy? Please forgive me, I’m fairly new to Xojo and asking really basic questions I know.

Thanks!
Dave

Is the question how you can access a file given only its posix path?

dim f as new FolderItem( pathToFile, FolderItem.PathTypeNative )

You use TextInputStream in Console apps, too.

This is a Function that I use to open and read a small config file in my console app. HTH.

  // CFG File will be generated by Installation Script
  Dim CFGfile As FolderItem
  Dim TIS as TextInputStream
  
  CFGfile = SpecialFolder.UserHome
  
  if CFGfile <> nil AND CFGfile.Exists AND CFGfile.Directory then
    CFGfile = SpecialFolder.UserHome.Child("ICPBaseDir")
    if CFGfile <> nil then
      if CFGfile.Directory then
        CFGfile = CFGfile.Child("ICP.cfg")
        if CFGfile <> nil then
          if not CFGfile.Directory then
            if CFGfile.Exists then
              Try
                TIS = TextInputStream.Open(CFGFILE)
                TIS.Encoding = Encodings.ISOLatin1
                Dim CFGString as String = TIS.ReadAll
                Return CFGString
              Catch e As IOException
                TIS.Close
                mSystemLog("1","(CFG)","CFG File IO Exception Error")
                 Return "failure"
              End Try
            end if
          end if
        end if
        
      end if
    end if
  end if