Created
March 5, 2011 14:31
-
-
Save okonomi/856388 to your computer and use it in GitHub Desktop.
temporary directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://codezine.jp/article/detail/1051 | |
function deleteDir($dir) | |
{ | |
$iterator = new RecursiveDirectoryIterator($dir); | |
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) { | |
if ($file->isDir()) { | |
rmdir($file->getPathname()); | |
} else { | |
unlink($file->getPathname()); | |
} | |
} | |
rmdir($dir); | |
} | |
$tempdir = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid(); | |
mkdir($tempdir); | |
echo $tempdir, PHP_EOL; | |
deleteDir($tempdir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use File::Temp; | |
my $dir = File::Temp->newdir(); | |
print $dir->dirname . "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tempfile | |
import shutil | |
temp = tempfile.mkdtemp(); | |
print temp | |
shutil.rmtree(temp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'temp_dir' | |
dir = TempDir.create | |
puts dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment