# class KTempDir

###

Module | kdecore
Namespace |
Class | KTempDir
Inherits |

\class KTempDir ktempdir.h <KTempDir>

Create a unique directory for temporary use.

The KTempDir class creates a unique directory for temporary use.

This is especially useful if you need to create a directory in a world writable directory like /tmp without being vulnerable to so called symlink attacks.

KDE applications, however, shouldn't create files or directories in /tmp in the first place but use the "tmp" resource instead. The standard KTempDir constructor will do that by default.

To create a temporary directory that starts with a certain name in the "tmp" resource, one should use: KTempDir(locateLocal("tmp", prefix));

KTempDir does not create any missing directories, but locateLocal() does.

See also KStandardDirs

See also KTemporaryFile Author Joseph Wenninger <jowenn@kde.org>

### methods

- KTempDir (directoryPrefix, mode)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  directoryPrefix | QString | QString()
  mode | int | 0700

  Creates a temporary directory with the name: \<directoryPrefix\>\<six letters\>

  The default directoryPrefix is "$KDEHOME/tmp-$HOST/appname"

  directoryPrefix - the prefix of the file name, or QString() for the default value

  mode - the file permissions, almost always in octal. The first digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the second selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values.

- KTempDir (a0)

  returns ctor
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  a0 | KTempDir |

- KTempDir (a0, a1)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | QString | QString()
  a1 | int | 0700

- autoRemove ( )

  returns bool

  Returns whether auto remove is active

  See also setAutoRemove

- create (directoryPrefix, mode)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  directoryPrefix | QString |
  mode | int |

  Creates a "random" directory with specified mode

  directoryPrefix - to use when creating temp directory (the rest is generated randomly)

  mode - directory permissions Returns true upon success

- exists ( )

  returns bool

  Returns true if a temporary directory has successfully been created and has not been unlinked yet.

- name ( )

  returns QString

  Returns the full path and name of the directory, including a trailing '/'. Returns The name of the directory, or QString() if creating the directory has failed or the directory has been unlinked

- removeDir (path)

  returns bool
  static

  Argument | Type | Default
  --- | --- | ---
  path | QString |

  Remove a directory and all its contents

  Remove recursively a directory, even if it is not empty or contains other directories.

  However the function works too when the path given is a non-directory file. In that case it simply remove that file.

  The function stops on the first error.

  This function is more meant for removing a directory not created by the user. For user-created directories, using KIO.NetAccess.del is recommended instead, especially as it has user feedback for long operations.

  path - Path of the directory to delete Returns true if successful, otherwise false (Use errno for more details about the error.) To do: decide how and where this function should be defined in KDE4

- setAutoRemove (autoRemove)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  autoRemove | bool |

  Turn automatic deletion of the directory on or off. Automatic deletion is on by default.

  autoRemove - toggle automatic deletion on or off

- status ( )

  returns int

  Returns the status of the directory creation based on errno. (see errno.h)

  You should check the status after object creation to check whether the directory could be created.

  Returns the errno status, 0 means ok

- unlink ( )

  returns Nothing

  Deletes the directory recursively