$dir = '/path/to/directory'; $files = scandir($dir); foreach($files as $file) { if(is_file($dir.'/'.$file)) { echo $file."\n"; } }
$file = '/path/to/file'; if(file_exists($file)) { unlink($file); }This code deletes the file specified by "/path/to/file", but only if it exists. The "file_exists()" function is used to check if the file exists, and the "unlink()" function is used to delete it. Package/library: The PHP "File" library is part of the core PHP language. There are no additional packages or libraries required to use it.