ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I think that needs to be double quotes because of the spaces
Incorrect, since there are no expansions inside the quotes, there is no difference between '' and "". The quoting is there to prevent the shell from globbing the *. Regardless, that way of using find does not work for the problem at all, and does not properly handle newlines in filenames.
It's important to use [:upper:] and [:lower:] in tr due to locale oddities.
If you learn python you will have little trouble with bash scripting.
But if you looked at man find as mentioned your problem would already be solved
a little help
Code:
find . -name '*.mp3' | sed ...
I think that needs to be double quotes because of the spaces
Code:
find . -name "*.mp3" | sed ...
Actually, you must use single quotes because you want the wildcard characters to be passed on to find, instead of being processed by bash.
Well, here I bring you an alternative.
My friend T. Hlaing, wrote me:
Quote:
You can easily hack my script ( http://gtk-apps.org/content/show.php?content=87601 ) to suit your needs.
If you enable "Recursive" option, it will automatically include subfolders (except for patternize option).
For each file, to get a new name for it, get_new_name function will be called.
All you need to do is modify it to suit your needs.
For instance, if you want to modify "First Letter Upper case" to suit your case, you will need to change this code segment.
elif self.misc_opt == FIRST_CAP:
name = name.capitalize() /* Change this line */
Just an example in bash for your reference. You need bash 4.0 for this
Code:
#!/bin/bash
function renamefiles {
if [[ BASH_VERSINFO -lt 4 ]]; then
echo "You need bash 4+ to make this script work."
return 1
fi
while read PATH; do
FILE=${PATH##*/}
DIR=${PATH%/*}
if [[ $FILE == *-* ]]; then
LEFT=${FILE%%-*}
LEFT_UPPER=${LEFT:0:1}
LEFT_UPPER=${LEFT_UPPER^^}
LEFT_LOWER=${LEFT:1}
LEFT_LOWER=${LEFT_LOWER,,}
LEFT=${LEFT_UPPER}${LEFT_LOWER}
RIGHT=${FILE#*-}
RIGHT_UPPER=${RIGHT:0:1}
RIGHT_UPPER=${RIGHT_UPPER^^}
RIGHT_LOWER=${RIGHT:1}
RIGHT_LOWER=${RIGHT_LOWER,,}
RIGHT=${RIGHT_UPPER}${RIGHT_LOWER}
FILE=${LEFT}-${RIGHT}
else
FILE=${FILE%%-*}
FILE_UPPER=${FILE:0:1}
FILE_UPPER=${FILE_UPPER^^}
FILE_LOWER=${FILE:1}
FILE_LOWER=${FILE_LOWER,,}
FILE=${FILE_UPPER}${FILE_LOWER}
fi
echo "renaming $PATH to $FILE..."
mv "$PATH" "$DIR/$FILE" || {
while read -t 0.2 -n 1; do continue; done # flush keyboard buffer
echo 'An error has occurred. Press ^C to cancel or any other key to continue.'
read -n 1
}
done < <(exec find -type f -name '*.mp3')
}
renamefiles
edit: revised to work with filenames that doesn't contain '-'.
Last edited by konsolebox; 03-12-2010 at 01:41 AM.
I think now with your script, with that of GrapefruiTgirl, with that of grail, and that of D. Ciabrini, we have enough to start working on a GTK interface.
To be honest, what really would make me happy is if someone could implement all of these scripts (fused into one) in the existing program pyRenamer ( http://www.infinicode.org/code/pyrenamer/ ).
I want to clarify that before posting this thread, I had long conversations with the author (in Castilian), and he said he had left the project due to lack of time. Not even offering money, I could convince implement this feature ... Really a shame.
I want to thank all contributors for, just how small contributions have made so far.
Last edited by pkramerruiz; 03-12-2010 at 07:07 AM.
I think now with your script, with that of GrapefruiTgirl, with that of grail, and that of D. Ciabrini, we have enough to start working on a GTK interface.
To be honest, what really would make me happy is if someone could implement all of these scripts (fused into one) in the existing program pyRenamer ( http://www.infinicode.org/code/pyrenamer/ ).
I want to clarify that before posting this thread, I had long conversations with the author (in Castilian), and he said he had left the project due to lack of time. Not even offering money, I could convince implement this feature ... Really a shame.
I want to thank all contributors for, just how small contributions have made so far.
Hey a thousand is way too much but 'course you're welcome. The script is even just a prototype. Just now I even found a bug.. RIGHT* will just hit a space and will not convert the first letter to uppercase.
Regarding pyRenamer I'm glad if I can help too but, too bad I don't do python and I also have no plans learning it yet. My target interpreter language is only Perl and Ruby. Just my taste and hope it's no offense to others.
Maybe you should try posting a request on a python forum?
...too bad I don't do python...yet. My target interpreter language is only Perl and Ruby.
If you think its a good idea:
I thought that with the help of my friend D.Ciabrini, you (both) might do an interface? I think some of this forum will lay a hand ...
I have no idea whether it is possible to interface with Pearl, but he knows a lot of Pearl ... Of course, he does not have much free time ...
If you think its a good idea:
I thought that with the help of my friend D.Ciabrini, you (both) might do an interface? I think some of this forum will lay a hand ...
I have no idea whether it is possible to interface with Pearl, but he knows a lot of Pearl ... Of course, he does not have much free time ...
Sorry but I'm also not yet good with Perl and Ruby and I don't go online often so I don't think I'll be capable of doing that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.