```{index} single: newdir; File::Temp function ``` ```{index} single: File::Temp::newdir; Perl function ``` # newdir Construct a `File::Temp::Dir` object wrapping a newly created temporary directory. ## Synopsis ```perl my $dir = File::Temp->newdir; my $dir = File::Temp->newdir('buildXXXXXX', DIR => '/var/tmp', CLEANUP => 0); ``` ## What you get back A blessed `File::Temp::Dir` object. It stringifies to the directory path, and its destructor removes the directory tree when `CLEANUP` is true (the default) and the current process matches the creating pid. ## Options Same as `tempdir` except `CLEANUP` defaults to true. The object records the creator pid so child processes do not accidentally delete a parent's directory on exit. ## Examples ```perl my $dir = File::Temp->newdir; open my $fh, '>', "$dir/scratch"; # $dir stringifies ## $dir and its contents are removed when $dir goes out of scope ``` ```perl my $dir = File::Temp->newdir(CLEANUP => 0); # keep the tree ``` ## Edge cases - Forked children do not clean up the parent's directory. - `$File::Temp::KEEP_ALL = 1` suppresses removal on destruction. ## Differences from upstream Fully compatible with upstream `File::Temp` 0.2312. ## See also - `tempdir` — functional counterpart returning a plain path string. - `dirname` — method on the returned object returning the path. - `unlink_on_destroy` — toggle cleanup on a per-object basis. - `File::Temp->new` — file counterpart.