Got stuck

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there -- did you try the find command with a few tweaks?:
To translate the files, try this ugly and untested line of code:

find topdir -type f -exec "{ bd=`basedir '{}'`; bf=`basename '{}'`; cd $bd; 
mv $bf `echo $bf|sed -e 's/-/_/g'` }" -print

Now as for the directories, I suppose you could use the same strategy with 
the following modification to be sure the deepest nested directories are 
translated first:

find topdir -depth -type d -print | sort -r >tempfile
for $D in `cat $tempfile`; do
    bd=`basedir $D`; bf=`basename$D`; cd $bd
    mv $bf `echo $bf | sed -e 's/-/_/g'`
done


As I said, this is untested, but it is intended to avoid accidental 
translation of a directory too soon in the process.

Perhaps the first and second find commands could be merged into one script:

find topdir -depth -print | sort -r >tempfile

and then use the for loop on all files regardless of whether they are plain 
files or directories. This would also take in special files like FIFO's or 
symbolic links or whatever.

Anyway, have fun and happy hacking.
--le

----- Original Message ----- 
From: "Pawel Loba" <pawel.loba@xxxxxxxxx>
To: "Speakup is a screen review system for Linux." <speakup at braille.uwo.ca>
Sent: Saturday, December 30, 2006 7:40 AM
Subject: Got stuck


Hello all.
I need to rename a number of directories (in the range of 1000) and all of
the mp3 files included in this directories (over 20000). What I want to
achieve
is to replace all of the dashes with underline sign.
Some time ago I found a script to rename files this way within a given
directory which looks as follows:

for i in *.mp3;
do
mv "$i" `echo $i | tr "-" "_"`;
done

This script works very well within a given directory but doesn't want to
work from the top directory witch actually includes this nearly 1000
subdirectories.
As an example, I'm getting somthing like this:
mv: cannot move `./Kolakowski-Leszek-Klucz-niebieski/01-klucz-niebieski.mp3'
to `./Kolakowski_Leszek_Klucz_niebieski/01_klucz_niebieski.mp3': no such
file
or directory

It was suggested to me to replace *.mp3 with `find . -name '*.mp3'`
But unfortunately, it did not work.
I'm not a programmer just a user who tries to be smart, so, please be
patient and treat me like a newbie. :-)

hope all of you on here have a great new year.
Thanks,
Pawel.


_______________________________________________
Speakup mailing list
Speakup at braille.uwo.ca
http://speech.braille.uwo.ca/mailman/listinfo/speakup





[Index of Archives]     [Linux for the Blind]     [Fedora Discussioin]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]
  Powered by Linux