Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I also have a website that needs to regularly convert large numbers of file names back and forth between character sets. While a text editor can do this, a portable solution using 2 steps in php was preferrable. First, add the filenames to an array, then do the search and replace. An extra piece of code in the function excludes certain file types from the array.</p> <pre><code>Function listdir($start_dir='.') { $nonFilesArray=array('index.php','index.html','help.html'); //unallowed files &amp; subfolders $filesArray = array() ; // $filesArray holds new records and $full[$j] holds names if (is_dir($start_dir)) { $fh = opendir($start_dir); while (($tmpFile = readdir($fh)) !== false) { // get each filename without its path if (strcmp($tmpFile, '.')==0 || strcmp($tmpFile, '..')==0) continue; // skip . &amp; .. $filepath = $start_dir . '/' . $tmpFile; // name the relative path/to/file if (is_dir($filepath)) // if path/to/file is a folder, recurse into it $filesArray = array_merge($filesArray, listdir($filepath)); else // add $filepath to the end of the array $test=1 ; foreach ($nonFilesArray as $nonfile) { if ($tmpFile == $nonfile) { $test=0 ; break ; } } if ( is_dir($filepath) ) { $test=0 ; } if ($test==1 &amp;&amp; pathinfo($tmpFile, PATHINFO_EXTENSION)=='html') { $filepath = substr_replace($filepath, '', 0, 17) ; // strip initial part of $filepath $filesArray[] = $filepath ; } } closedir($fh); } else { $filesArray = false; } # no such folder return $filesArray ; } $filesArray = listdir($targetdir); // call the function for this directory $numNewFiles = count($filesArray) ; // get number of records for ($i=0; $i&lt;$numNewFiles; $i++) { // read the filenames and replace unwanted characters $tmplnk = $linkpath .$filesArray[$i] ; $outname = basename($filesArray[$i],".html") ; $outname = str_replace('-', ' ', $outname); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload