matt121400 Posted June 17, 2011 Share Posted June 17, 2011 Hello so somehow their are a ton of random phpfiles with numbers behind them then were created when replacing files that look like this test.php1323434435 and i am looking to delete them. I have created this which works for deleting them when its in the same folder <?php $files = glob('test.php1*'); array_map('unlink', $files); ?> my question is how do i get it to search all the subdirectories and do the same thing Link to comment https://forums.phpfreaks.com/topic/239621-php-search-subdirectories-and-delete-files/ Share on other sites More sharing options...
WebStyles Posted June 17, 2011 Share Posted June 17, 2011 You can loop through the files and search for the folders with is_dir() Of course, this depends on how many levels of folders we're talking about. if ($handle = opendir('/path/to/files')) { while (false !== ($file = readdir($handle))) { if(is_dir($file)){ // found a folder, do something with it } } closedir($handle); } Link to comment https://forums.phpfreaks.com/topic/239621-php-search-subdirectories-and-delete-files/#findComment-1231003 Share on other sites More sharing options...
redixx Posted June 17, 2011 Share Posted June 17, 2011 Honestly PHP isn't the most efficient tool to do this with. If it's only a small amount of files, sure. Otherwise use the python command line, with a regex expression or something. Link to comment https://forums.phpfreaks.com/topic/239621-php-search-subdirectories-and-delete-files/#findComment-1231030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.