Skip to content

Instantly share code, notes, and snippets.

@juananruiz
Last active March 30, 2020 10:27
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 juananruiz/a09a1e86c63ef5f6b5b0ccafbed57a97 to your computer and use it in GitHub Desktop.
Save juananruiz/a09a1e86c63ef5f6b5b0ccafbed57a97 to your computer and use it in GitHub Desktop.
Script para renombrar masivamente los archivos de una carpeta cuando el comando rename de linux no es suficiente
<?php
$directorio = opendir(__DIR__);
mkdir ($directorio . '/renombrados');
while ($archivo = readdir($directorio)) {
if (!is_dir($archivo) AND strpos($archivo, '.jpg')) {
$numero = (int) substr($archivo, strpos($archivo, '_') + 1, -4);
if (0 === $numero % 2) {
$archivo_nuevo = 'renombrados/obra_' . (string)($numero / 2) . '_imagen.jpg';
} else {
$archivo_nuevo = 'renombrados/obra_' . (string)round($numero / 2) . '_ficha.jpg';
}
echo $archivo . ' >>> ' . $archivo_nuevo . "\n";
rename($archivo, $archivo_nuevo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment