xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

StrFile()

Writes a string to a file starting at a specified position.

Syntax

StrFile( <cString>      , ;
         <cFileName>    , ;
        [<lUseExisting>], ;
        [<nOffset>]     , ;
        [<lTruncate>]     ) --> nBytesWritten

Arguments

<cString>
This is a character string to be written to the file <cFileName>.
<cFileName>
This is a character string holding the name of the file to write to. It must include path and file extension. If the path is omitted from <cFileName>, the file is searched in the current directory only.
<lUseExisting>
This parameter defaults to .F. (false) so that a new file is created. To write <cString> to an existing file, <lUseExisting> must be set to .T. (true).
<nOffset>
This optional numeric parameter specifies the starting position for writing. It defaults to the end-of-file.
<lTruncate>
This parameter defaults to .F. (false). When set to .T. (true), the file is truncated after <cString> is written, i.e. the file ends with <cString>.

Return

The function returns the number of bytes written to the file as a numeric value.

Info

See also:CSetSafety(), FileStr(), FWrite()
Category: CT:DiskUtil , File functions , Low level file functions
Source:ct\strfile.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example writes the names of all PRG files of the current directory
// to a file.

   PROCEDURE Main
      LOCAL cFileName := "Prg_files.txt"
      LOCAL aFiles    := Directory( "*.prg" )
      LOCAL aFile

      FOR EACH aFile In aFiles
         StrFile( aFile[1] + HB_OsNewLine(), ;
                  cFileName, .T. )
      NEXT
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe