Last active
March 30, 2020 10:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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