Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - createtempfile() create a file with unique name http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 createtempfile()    Create a file with unique name
------------------------------------------------------------------------------
 Declaration
   file.hdr

 Syntax
   func logical createtempfile extern
   param char cPathName

 Arguments
   cPathName is the path to create a file name for. The path must be
   terminated with a '\' character.

 Return
   A logical indicating the success of operation.

 Description
   This function creates a file with unique name in the specified
   directory.

   The file name is appended to the input path passed in the cPathName
   parameter. The parameter cPathName must be long enough to allow
   for at least 13 additional characters after the path because the
   function expands the contents of this parameter by the name of the
   created file.

   The created temporary file is zero byte long and is closed when
   the function returns. The file is not deleted by the function.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   proc Test_createtempfile
   // Create a temporary file in the temporary path
   vardef
      char   cFile
      _HFILE hTemp
   enddef
   cFile := getenv( "TEMP" )        // get temporary directory name
   if .not. isempty( cFile )        // if target directory exists
      cFile += "\"                  // append path separator
      if createtempfile( cFile )    // create file
         fbopen( hTemp, cFile, FB_WRITE ) // use the file in a meaningful way
         fbwriteln( hTemp, "This is written to the temporary file" )
         fbclose( hTemp )
         type cFile
         erase cFile                // clean up
      else
         ? "Cannot create temporary file"
      endif
   else
      ? "Temporary directory does not exist"
   endif
   endproc

   proc main
   Test_createtempfile()
   endproc

See Also: exist()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson