Se avete dubbi o domande sulla programmazione in generale, fatele qui

Messaggio9 novembre 2011, 1:41 - I nostri script bash #108421

Bel thread ;)
Ecco uno script per rinominare ricorsivamente da uppercase in lowercase trasformando gli spazi in underscore directory e file a partire dalla directory corrente. Non l'ho scritto io ma mi è stato molto utile.

Codice: Seleziona tutto
#!/bin/bash

#
# Filename: rename.sh
# Description: Renames files and folders to lowercase recursively
#              from the current directory
# Variables: Source = x
#            Destination = y

#
# Rename all directories. This will need to be done first.
#

# Process each directory's contents before the directory  itself
find * -depth -type d | while read x
do

        # Translate Caps to Small letters
        y=$(echo "$x" | tr '[A-Z ]' '[a-z_]');

        # create directory if it does not exit
        if [ ! -d "$y" ]; then
                mkdir -p "$y";
        fi

        # check if the source and destination is the same
        if [ "$x" != "$y" ]; then

                # move directory files before deleting
                ls -A "$x" | while read i
                do
                  mv "$x"/"$i" "$y";
                done
                rmdir "$x";

        fi

done

#
# Rename all files
#
find * -type f | while read x ;
do
        # Translate Caps to Small letters
        y=$(echo "$x" | tr '[A-Z ]' '[a-z_]');
        if [ "$x" != "$y" ]; then
                mv "$x" "$y";
        fi
done

exit 0
"It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away".
Antoine de Saint Exupéry
http://www.keepsimple.it
Avatar utente
lgaggini
Arciere
 
Messaggi: 277
Iscritto il: 21 gennaio 2011, 0:46
Località: Pescia (PT)
Top

Messaggio9 novembre 2011, 1:49 - I nostri script bash #108424

@ Lorenzo: scusami, sarà l'ora tarda, ma non ho ben capito a che serve il tuo script e come si usa...
Avatar utente
TheImmortalPhoenix
Arciere Provetto
 
Messaggi: 523
Iscritto il: 16 gennaio 2011, 17:14
Località: 127.0.0.1
Top

Messaggio9 novembre 2011, 2:09 - I nostri script bash #108426

modifica i nomi di tutti i file e le directory ricorsivamente a partire da quella in cui viene eseguito, rinominandoli tutti in minuscolo e sostituendo gli spazi vuoti presenti nei nomi con un underscore "_" , visto che il blank spesso può essere scomodo.
Se avete risolto il vostro problema, aggiungete [Risolto]+Spazio_Bianco al titolo del primo post del thread.
Offertissima: Mi Vendo!!! Cercasi lavoro (qualunque, tra quelli leciti) in tutta italia da Roma in su.
Avatar utente
4javier
Moderatore
 
Messaggi: 6076
Iscritto il: 5 ottobre 2008, 17:19
Top


Torna a Programmazione

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

Moderatori: 4javier, aleph, veleno77, adriano, Hilinus