getDownloadsDirectory(); if (!is_dir($dir)) { return; } $extension = ".wpstg"; // Extension of the file created when download starts. if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (strpos($file, $extension) !== false) { unlink($dir . '/' . $file); } } closedir($dh); } } }