CreateFile()

Syntax

Result = CreateFile(#File, Filename$)
Description
Create an empty file. If the file already exists, it will be opened and replaced by blank content! Be careful.

If #PB_Any is used as '#File' parameter, the new file number will be returned as 'Result'.

If 'Result' is not 0, the file has been effectively created, else the creation has failed. The result must always be tested, since performing operations on a non-created file will cause a severe crash.

If the #File was already used, the previous file will be closed automatically.

Example:


  If CreateFile(0, "Text.txt")         ; we create a new text file...
    For a=1 To 10
      WriteStringN(0, "Line "+Str(a))  ; we write 10 lines (each with 'end of line' character)
    Next
    For a=1 To 10
      WriteString(0, "String"+Str(a))  ; and now we add 10 more strings on the same line (because there is no 'end of line' character)
    Next
    CloseFile(0)                       ; close the previously opened file and store the written data this way
  Else
    MessageRequester("Information","may not create the file!")
  EndIf

Supported OS

All

<- CloseFile() - File Index - Eof() ->