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 Quote Link to comment 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); } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.