bilis_money Posted March 18, 2008 Share Posted March 18, 2008 Hi guys Let say i have 5 files and all of them has the .swf extension filename. now how do i delete them properly by just calling one statement? i tried the code below but it did not work. <?php unlink("*.swf"); ?> thank you in advance. Link to comment https://forums.phpfreaks.com/topic/96682-very-simple-deletion-question/ Share on other sites More sharing options...
Cep Posted March 18, 2008 Share Posted March 18, 2008 You cannot do a batch deletion with a wildcard using the unlink method, you must loop through the files you wish to delete. Link to comment https://forums.phpfreaks.com/topic/96682-very-simple-deletion-question/#findComment-494749 Share on other sites More sharing options...
moon 111 Posted March 18, 2008 Share Posted March 18, 2008 This should work: <?php $dir = './dir/'; // The directory must have '/' at the end! $arr = scandir($dir); foreach($arr as $value) { if(strstr($value, '.swf')) { unlink($dir . $value); } } ?> Link to comment https://forums.phpfreaks.com/topic/96682-very-simple-deletion-question/#findComment-494758 Share on other sites More sharing options...
bilis_money Posted March 18, 2008 Author Share Posted March 18, 2008 can you show me some example codes please. thank you. Link to comment https://forums.phpfreaks.com/topic/96682-very-simple-deletion-question/#findComment-494761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.