Anyone know a snippet of this?
I need to delete all files in a folder but not jpg,gif or png files.
:sweat:
Sorcher
6
Junior Poster
Recommended Answers
Jump to PostHey,
How about trying something like this:
$excludeExtensions = array('jpg', 'gif', 'png'); $directory = '/path/to/directory'; $files = scandir($directory); foreach($files as $file) { if(!in_array(pathinfo($file, PATHINFO_EXTENSION), $excludeExtensions))) { unlink("{$directory}/{$file}"); } }
This code will iterate through all of the files found in a target directory. It will then …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.