CreateFile()

语法

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.

返回值

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.

Remarks

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)
    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

参阅

OpenFile(), ReadFile(), CloseFile()

已支持操作系统

所有

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