Skip to content

Instantly share code, notes, and snippets.

@ariews
Last active December 14, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariews/5153279 to your computer and use it in GitHub Desktop.
Save ariews/5153279 to your computer and use it in GitHub Desktop.
<?php
$directory_to_check = '/path/to/dir';
$DTs = array(realpath($directory_to_check));
$DSc = array();
while (count($DTs) > 0)
{
foreach ($DTs as $DKy => $std)
{
if ($dir = @opendir($std))
{
while (($file = readdir($dir)) !== false)
{
if (($file != '.') && ($file != '..'))
{
$RPT = realpath($std.'/'.$file);
if (is_dir($RPT))
{
if (!in_array($RPT, $DSc) && !in_array($RPT, $DTs))
{
$DTs[] = $RPT;
}
}
elseif (is_file($RPT))
{
$FId[] = $RPT;
}
}
}
closedir($dir);
}
$DSc[] = $std;
unset($DTs[$DKy]);
}
}
$FId = array_unique($FId);
sort($FId);
function gnf($nfl)
{
$nfl = str_replace("{", "(", $nfl);
$nfl = str_replace("}", ")", $nfl);
$nfl = str_replace("[", "(", $nfl);
$nfl = str_replace("]", ")", $nfl);
$nfl = str_replace("`", "", $nfl);
$nfl = str_replace("!", "", $nfl);
return $nfl;
}
foreach ($FId as $fnm)
{
if ( rename($fnm, gnf($fnm)) )
{
echo "SUKSES!!!n";
}
else
{
echo "--- GAGAL ---n";
echo $fnm ."n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment