> convert to >> stroem_kluber_2008.pdf Generally in filename avoid the chars: # < > + = % ! ' " & * ^ | { } / \ : @ . , [ ] ( ) ; ? ¢ ™ $ ® Mit Vorsicht verwenden, das ist ein mächtiges Werkzeug! Bist du auf eigene Gefahr !! **************************************************************** by rotasul.net */ header ('Content-type: text/html; charset=UTF-8'); $slash = '/'; function cleanname($nm,$limp_n){ // $limp_n >>> r_llll m_llll c_llll $j = array(); $nm = str_replace('c++','cpp', $nm); if(strstr($nm,'_dddd_')){ $j = explode('_dddd_',$nm); $nm = $j[0]; } if(strstr($nm,'_llll_')){ $j = explode('_llll_',$nm); $nm = $j[0].$j[1]; } $accent = array('æ','Æ','Ñ','ñ','Á','À','Â','Ã','Ä','Ç','ç','È','É','Ê','Ë','Í','Í','Ò','Ó','Ô','Ö','Ù','Ú','Ü','à','á','â','ã','ä','è','é','ê','ë','ì','í','ò','ó','ô','õ','ö','ù','ú','ü'); // use >> print_r($accent); >> system accent test $noaccent = array('a','a','N','n','A','A','A','A','A','C','c','E','E','E','E','I','I','O','O','O','O','U','U','U','a','a','a','a','a','e','e','e','e','i','i','o','o','o','o','o','u','u','u'); $nm = str_replace($accent,$noaccent,$nm); $sz_nm = strlen($nm); for($i = 0; $i < $sz_nm;++$i){ $ordn = ord($nm[$i]); // ord generate the ascii number if( $ordn < 48 ) $nm[$i] = '_'; if( $ordn > 57 && $ordn < 65) $nm[$i] = '_'; if( $ordn >= 65 && $ordn <= 90) $nm[$i] = chr($ordn + 32); // CAPS + 32 = stringtolower if( $ordn > 90 && $ordn < 97) $nm[$i] = '_'; // 97 - 122 a - z if( $ordn > 122 ) $nm[$i] = '_'; // clean all } while(strstr($nm,'__')){ $nm = str_replace('__','_',$nm); } $nm = rtrim($nm,'_'); $nm = ltrim($nm,'_'); $sz_nm = strlen($nm); if( $sz_nm > 60 && $limp_n == 'm_llll' ) $nm = substr($nm,0,59).'_llll_'.substr($nm,60,$sz_nm); if( $sz_nm > 60 && $limp_n == 'c_llll' ) $nm = substr($nm,0,59); return $nm; } function renfile($dir,$orig_name,$limp_n,$file_type,$slash,$repl_from,$repl_to){ $r_file = $nm = $newn = $ext = ''; $fim = 0; $sz_orig_name = strlen($orig_name); for ($i = 0; $i < $sz_orig_name; ++$i) if(ord($orig_name[$i]) == 46) $fim = $i; // find the point '.' ascii 46 if( $sz_orig_name > $fim && $fim > 0 ){ $sz_orig_name = $sz_orig_name - $fim; $ext = substr($orig_name,$fim,$sz_orig_name); $nm = substr($orig_name,0, $fim); } $ext = strtolower($ext); if( strlen($nm) > 0 && ($file_type == $ext || $file_type == '.all' )){ $newname = cleanname($nm,$limp_n); if($repl_from != 'none' && $repl_to != 'none') $newname = str_replace($repl_from,$repl_to,$newname); $newn = $newname; $ext = ($ext == '.jpeg') ? '.jpg' : $ext; $newname .= $ext; if($nm != $newn){ // old_name == new_name if(file_exists($dir.$slash.$newname)){ $tx = rand(10000,99999); rename ($dir.$slash.$orig_name,$dir.$slash.$newn.'_dddd_'.$tx.'_'.$ext ); $r_file = ''.$newn.'_dddd_'.$tx.'_'.$ext.'
'; // duplicated file }else{ rename ($dir.$slash.$orig_name,$dir.$slash.$newname ); $r_file = ''.$newname.'
'; } }else{ $r_file = ''.$newname.'
';}// no modification }else{ $r_file = ''.$orig_name.'
'; }// no extension or just extension return $r_file; } function whois($dir,$x,$limp_n,$file_type,$sb,$slash,$repl_from,$repl_to){ $ret = ''; $path = (strlen($x) > 0) ? $dir.$slash.$x : $dir; if(is_dir($path)){ $u = scandir($path); foreach($u as $orig_name){ if($orig_name != '.' && $orig_name != '..'){ if(is_dir ($path.$slash.$orig_name)) $sb = whois($path,$orig_name,$limp_n,$file_type,$sb,$slash,$repl_from,$repl_to); if(is_file($path.$slash.$orig_name)) $sb[$path][$orig_name] = renfile($path,$orig_name,$limp_n,$file_type,$slash,$repl_from,$repl_to); } } } return $sb; } $dirget = $flag_dir = $flag_file = $file_type = $u = $repl_from = $repl_to = ''; $renf = array(); if (isset($_GET['dirtoget']) && isset($_GET['filetype'])){ $dirget = trim($_GET['dirtoget']); if(strstr($dirget,'./') || strlen($dirget) < 4) $dirget = ''; if(strlen($dirget) > 1 && is_dir($dirget)) $flag_dir = 'ok'; else $u = '

Typed in dir: '.$_GET['dirtoget'].'

'; $file_type = trim($_GET['filetype']); $file_type = strtolower($file_type); if( strlen($file_type) > 1 && $file_type[0] == '.') $flag_file = 'ok'; } if($flag_dir = 'ok' && $flag_file == 'ok' ){ $limp_n = (strlen($_GET['limp_n']) > 0) ? $_GET['limp_n'] : 'none'; $repl_from = trim($_GET['replace_from']); $repl_to = trim($_GET['replace_to']); $repl_from = ($repl_from == 'none' || strlen($repl_from) == 0) ? 'none': $repl_from; $repl_to = ($repl_to == 'none' || strlen($repl_to) == 0) ? 'none': $repl_to; $renf = whois($dirget,'',$limp_n,$file_type,$renf,$slash,$repl_from,$repl_to); if (sizeof ($renf) > 0){ ksort($renf); foreach ($renf as $dir => $files){ $u .= '

'.$dir.'

'; foreach ($files as $old => $file){ if($file_type != '.all' && $_GET['view'] == 'ext' && strstr($file,$file_type)) $u .= '    '.$old.'   =>   '.$file.''; if($file_type == '.all' || $_GET['view'] == 'all') $u .= '    '.$old.'   =>   '.$file.''; } } } } $repl_from = ($repl_from == 'none')? '' : $repl_from; $repl_to = ($repl_to == 'none')? '' : $repl_to; echo '

Simple Name

A simple way to standardize the names of all files from a directory and subdirs. The root is protected, just dir allowed.
All files names with 0-9 a-z _ no uppercase chars, no white spaces and just underscore as separator
... and more ... recognize the mostly used accented characters and convert to equivalent lowercase, ones that are not recognized are transformed into underscores ... removes the uppercase in the extensions ... and change .jpeg to .jpg

It is a powerful tool, be careful ... before use in your documents directory make some tests it in a temp dir.



path:

Linux** /local/dir/name     Win e:/to_test

extension:

put one i.e.: .pdf .gif .htm .html    or   .all   (to all files extensions)

60 chars filename:
mark       remove mark     cut name     none

filename string change
from:
to:    
from "some string" to an empty string use "_" underscore in "to" field

View:
all       only extension


Blue: rename was not necessary
Red: file renamed
Red: long filename, recommended cut point is marked with _llll_
Red: duplicated filename, need further verification, is marked with _dddd_

Green: typed extension not found or only extension in filename
the extension is defined by the last point in the filename, then no changes in the files like: .htaccess


** remember: in external drives the Linux systems not allow some file operations, must move to local device!

'.$u.'


'; ?>