Result = CreateFile(#File, Filename$ [, Flags])
Create an empty file.


#File The number to identify the new file. #PB_Any can be used to auto-generate this number.
Filename$ The filename and path to the new file. If the filename does not include a full path, it is interpreted relative to the current directory.
Flags (optional) It can be a combination (using the '| operand) of the following values:
  #PB_File_SharedRead : the opened file can be read by another process (Windows only).
  #PB_File_SharedWrite: the opened file can be write by another process (Windows only).
  #PB_File_NoBuffering: the internal PureBasic file buffering system will be disabled for this file. 
                        FileBuffersSize() can not be used on this file.
combined with one of the following values (the following flags affect the WriteString()(), WriteStringN(), ReadString(), ReadCharacter() and WriteCharacter() behaviour):
  #PB_Ascii  : all read/write string operation will use ascii if not specified otherwise.
  #PB_UTF8   : all read/write string operation will use UTF-8 if not specified otherwise (default).
  #PB_Unicode: all read/write string operation will use Unicode if not specified otherwise.

Return value

Returns nonzero if the file was created successfully and zero if there was an error. If #PB_Any was used as the #File parameter then the new generated number is returned on success.


If the file already exists, it will be overwritten by the new empty file. The FileSize() function can be used to determine whether a file exists so the user can be prompted before overwriting a file.

To open an existing file for reading/writing, use the OpenFile() function. To open a file for reading only, use ReadFile().


  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)
    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)
    CloseFile(0)                       ; close the previously opened file and store the written data this way
    MessageRequester("Information","may not create the file!")

See Also

OpenFile(), ReadFile(), CloseFile()

Supported OS


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