https://www.icyphoenix.com/viewtopic.php?f=33&t=7167 ----------------------------------- Mighty Gorgon Tue 25 May, 2010 20:30 Copy A File In All Folders And SubFolders ----------------------------------- I have created this script a lot of time ago when I needed to update all [b]index.html[/b] files into my Icy Phoenix... doing it by hand would have required a lot of time, so I have created this: [code linenumbers=false syntax=php]' . "\n"); echo('' . "\n"); echo('Files List' . "\n"); echo('' . "\n"); $root_dir = './'; $exclude_array = array('install'); $source_file = 'install/index.html'; $files_list = create_files_list_full($root_dir, ''); foreach ($files_list as $file_element) { if (is_dir($file_element) && !in_array($file_element, $exclude_array)) { $tmp_paths = array(); $tmp_paths = explode('/', $file_element); $skip_sub_folder = false; for ($i = 0; $i < sizeof($tmp_paths); $i++) { for ($j = 0; $j < sizeof($exclude_array); $j++) { if ($exclude_array[$j] == $tmp_paths[$i]) { $skip_sub_folder = true; break; } } if ($skip_sub_folder == true) { break; } } if ($skip_sub_folder == false) { @unlink($file_element . '/index.html'); @copy($source_file, $file_element . '/index.html'); echo('• ' . $file_element . '
' . "\n"); flush(); } } } echo('' . "\n" . ''); // FUNCTIONS function create_files_list_full($dir, $extensions = '') { $directory = @opendir($dir); $files_list = array(); while (@$file = readdir($directory)) { if (!in_array($file, array('.', '..'))) { $is_dir = (is_dir($dir . '/' . $file)) ? true : false; $temp_path = str_replace('//', '/', ($dir . '/' . $file)); $file_details = get_file_details($temp_path); $file_title = $file_details['name']; $file_type = strtolower($file_details['ext']); $process_file = false; if ($extensions == '') { //$file_exclusions_array = array(); $file_exclusions_array = array('ace', 'bak', 'bmp', 'css', 'gif', 'hl', 'htc', 'htm', 'html', 'ico', 'jar', 'jpeg', 'jpg', 'js', 'pak', 'png', 'rar', 'sql', 'swf', 'tpl', 'ttf', 'txt', 'wmv', 'zip'); if (!in_array($file_type, $file_exclusions_array)) { $process_file = true; } } else { if ( $file_type == $extensions) { $process_file = true; } } if ($process_file == true) { $files_list[] = $temp_path; } // Directory found, so recall this function if ($is_dir) { $files_list = array_merge($files_list, create_files_list_full($dir . '/' . $file, $extensions)); } } // if } // while @closedir($directory); return $files_list; } /* * get_file_details * Get File Details: name, extension */ function get_file_details($file_name) { $file_details = array(); $file_tmp = str_replace ('http://', '', $file_name); $file_path[] = array(); $file_path = explode('/', $file_tmp); $file_details['name_full'] = $file_path[sizeof($file_path) - 1]; $file_part = explode('.', strtolower($file_details['name_full'])); $file_details['ext'] = $file_part[sizeof($file_part) - 1]; $file_details['name'] = substr($file_details['name_full'], 0, strlen($file_details['name_full']) - strlen($file_details['ext']) - 1); return $file_details; } ?>[/code] If you want to use this script, you just have to specify the file to be copied ([b]$source_file[/b]) and the paths you would like to exclude (if any...). Please note that this script will overwrite any file with the same name of the one you are going to copy, so make sure you use this script on a backup copy first. ----------------------------------- DWho Mon 06 Jun, 2011 17:03 Re: Copy A File In All Folders And SubFolders ----------------------------------- Thanks Luca will come in very handy when i get back on board shortly