---
title: "ftemp | open.mp"
description: "Creates a file in the \"tmp\", \"temp\" or root directory with random name for reading and writing."
canonical: https://omp.itsneufox.com/de/docs/scripting/functions/ftemp
language: de
---

# ftemp

## Description

Creates a file in the "tmp", "temp" or root directory with random name for reading and writing. The file is deleted after fclose() is used on the file.

## Returns

The temporary file handle. 0 if failed.

## Examples

```c
// Create a temporary file stream
new File:t_handle = ftemp();

// Declare "handle"
new File:handle;

// Declare "g_char"
new g_char;

// Check, if temporary file stream is open
if (t_handle)
{
    // Success

    // Open "file.txt" in "read only" mode and check, if the file is open
    if (handle = fopen("file.txt", io_read))
    {
        // Get all the characters from "file.txt"
        while ((g_char = fgetchar(handle, 0, false)) != EOF)
        {
            // Write character in lowercase into the temporary file stream
            fputchar(t_handle, tolower(g_char), false);
        }

        // Close "file.txt"
        fclose(handle);

        // Set the file pointer of the temporary file stream to the first byte
        fseek(t_handle, _, seek_begin);

        // Open "file1.txt" in "write only" mode, and check, if the file is open
        if (handle = fopen("file1.txt", io_write))
        {
            // Success

            // Get all the characters from the temporary file stream
            while ((g_char = fgetchar(t_handle, 0, false)) != EOF)
            {
                // Write character into "file1.txt"
                fputchar(handle, g_char, false);
            }

            // Close "file1.txt"
            fclose(handle);

            // Set the file pointer of the temporary file stream to the first byte
            fseek(t_handle, _, seek_begin);
        }
        else
        {
            // Error
            print("Failed to open file \"file1.txt\".");
        }

        // Open "file2.txt" in "write only" mode, and check, if the file is open
        if (handle = fopen("file2.txt", io_write))
        {
            // Success

            // Get all the characters from the temporary file stream
            while ((g_char = fgetchar(t_handle, 0, false)) != EOF)
            {
                // Write character into "file2.txt"
                fputchar(handle, g_char, false);
            }

            // Close "file2.txt"
            fclose(handle);
        }
        else
        {
            // Error
            print("Failed to open file \"file2.txt\".");
        }
    }
    else
    {
        // Error
        print("Failed to open file \"file.txt\".");
    }

    // Close the temporary file stream
    fclose(t_handle);
}
else
{
    // Error
    print("Failed to create a temporary file stream.");
}
```

## Notes

warnung

This function can crash the server when the right directory isn't created.

## Related Functions

-   [fopen](https://omp.itsneufox.com/de/docs/scripting/functions/fopen): Open a file.
-   [fclose](https://omp.itsneufox.com/de/docs/scripting/functions/fclose): Close a file.
-   [fremove](https://omp.itsneufox.com/de/docs/scripting/functions/fremove): Remove a file.
-   [fwrite](https://omp.itsneufox.com/de/docs/scripting/functions/fwrite): Write to a file.
-   [fread](https://omp.itsneufox.com/de/docs/scripting/functions/fread): Read a file.
-   [fputchar](https://omp.itsneufox.com/de/docs/scripting/functions/fputchar): Put a character in a file.
-   [fgetchar](https://omp.itsneufox.com/de/docs/scripting/functions/fgetchar): Get a character from a file.
-   [fblockwrite](https://omp.itsneufox.com/de/docs/scripting/functions/fblockwrite): Write blocks of data into a file.
-   [fblockread](https://omp.itsneufox.com/de/docs/scripting/functions/fblockread): Read blocks of data from a file.
-   [fseek](https://omp.itsneufox.com/de/docs/scripting/functions/fseek): Jump to a specific character in a file.
-   [flength](https://omp.itsneufox.com/de/docs/scripting/functions/flength): Get the file length.
-   [fexist](https://omp.itsneufox.com/de/docs/scripting/functions/fexist): Check, if a file exists.
-   [fmatch](https://omp.itsneufox.com/de/docs/scripting/functions/fmatch): Check, if patterns with a file name matches.
-   [ftell](https://omp.itsneufox.com/de/docs/scripting/functions/ftell): Get the current position in the file.
-   [fflush](https://omp.itsneufox.com/de/docs/scripting/functions/fflush): Flush a file to disk (ensure all writes are complete).
-   [fstat](https://omp.itsneufox.com/de/docs/scripting/functions/fstat): Return the size and the timestamp of a file.
-   [frename](https://omp.itsneufox.com/de/docs/scripting/functions/frename): Rename a file.
-   [fcopy](https://omp.itsneufox.com/de/docs/scripting/functions/fcopy): Copy a file.
-   [filecrc](https://omp.itsneufox.com/de/docs/scripting/functions/filecrc): Return the 32-bit CRC value of a file.
-   [fattrib](https://omp.itsneufox.com/de/docs/scripting/functions/fattrib): Set the file attributes.
-   [fcreatedir](https://omp.itsneufox.com/de/docs/scripting/functions/fcreatedir): Create a directory.
