ibanez270dx Posted August 14, 2006 Share Posted August 14, 2006 Hi, I'm trying to do an unlink command like so: unlink(*.xls) . It doesn't work and I have tried it with single and double quotes. Can anyone help me? Thanks! - Jeff Link to comment https://forums.phpfreaks.com/topic/17517-unlinking-whatever/ Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 Use the glob() function to generate an array of all .xls files in a folder.Loop through the array and unlink each one separately. Link to comment https://forums.phpfreaks.com/topic/17517-unlinking-whatever/#findComment-74525 Share on other sites More sharing options...
tomfmason Posted August 14, 2006 Share Posted August 14, 2006 try this.[code=php:0]$dir = "path/to/folder";foreach (glob($dir . "*.xls") as $files) { unlink($files);}[/code]Hope this helps,Tom Link to comment https://forums.phpfreaks.com/topic/17517-unlinking-whatever/#findComment-74529 Share on other sites More sharing options...
tomfmason Posted August 14, 2006 Share Posted August 14, 2006 You have to be careful with this. It will delete all of the files with the ext of xls in that folder and all sub folders. Link to comment https://forums.phpfreaks.com/topic/17517-unlinking-whatever/#findComment-74533 Share on other sites More sharing options...
ibanez270dx Posted August 14, 2006 Author Share Posted August 14, 2006 Thanks! I used this:[code=php:0]foreach (glob("*.xls") as $filename) { unlink($filename); }[/code]It works perfectly. And yes, I did need to delete all the files with a *.xls extension. Link to comment https://forums.phpfreaks.com/topic/17517-unlinking-whatever/#findComment-74552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.