Notices


Reply
Thread Tools
Posts: 21 | Thanked: 1 time | Joined on May 2010
#1
Hi!

I've been trying to rename multiple files in a folder and its subfolders using xterm without success. I only want to rename files called folder.jpg to files called test.jpg. There is only one folder.jpg in every folder (obviously).

At first i tried:

for file in 'folder.jpg' ;do
mv $file test.jpg
done

This works in one folder but doesn't take subfolders into account (and though trying I couldn't make it to). Then I tried:

find . -name 'folder.jpg' -exec (some renaming command)

I didn't even get to worry about what (some renaming command) might look like because busybox (xterm) doesn't even seem to recognize -exec (although the documentation for versio 1.16 says it does - the n900 is running 1.10, however).

At this point i got stuck, since the n900 is my first linux device. If anyone has some pointer for me as to how to proceed (or the correct code), i'd really appreciate it!

Thank you =)
Cheers pcerf
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#2
Use find with xargs.

I also miss the -exec flag on the N900. And to be verbose:

<find command> | xargs ...
 
eitama's Avatar
Posts: 702 | Thanked: 334 times | Joined on Feb 2010 @ Israel.
#3
i think it will be much easier for you to do it with python.
i always preferred python on bash.
__________________
| Developer of Horizontal-Call - Call your contacts, fast! |
| Reverse SSH - access your N900 from anywhere, anytime |
| Using Samsung Galaxy S GT-i9000 and Nokia N900 |
| DonateMe - If you feel I helped you in a very good way, feel free to donate |
 
Posts: 145 | Thanked: 237 times | Joined on Mar 2010 @ Helsinki
#4
There's no reason to get unnecessarily complicated if you know the depth in advance. Just use "*jpg */*jpg */*/*jpg" as your pattern.


Although obviously you would then need to edit the rest of your script to understand the resulting matches.

Last edited by jnwi; 2010-05-20 at 11:06.
 
eitama's Avatar
Posts: 702 | Thanked: 334 times | Joined on Feb 2010 @ Israel.
#5
This looks like a good place to start :

http://puschitz.com/pblog/?p=31
__________________
| Developer of Horizontal-Call - Call your contacts, fast! |
| Reverse SSH - access your N900 from anywhere, anytime |
| Using Samsung Galaxy S GT-i9000 and Nokia N900 |
| DonateMe - If you feel I helped you in a very good way, feel free to donate |
 
Posts: 21 | Thanked: 1 time | Joined on May 2010
#6
thanks a lot for your speedy and helpful answers!

with your help i was able to write the following script to make all folder.jpg hidden by renaming them to .folder.jpg. that way these album covers show up in media player but not in the picture gallery =)

#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

for file in $(find . -name 'folder.jpg'); do
newfile=$(echo $file | sed s/folder.jpg/.folder.jpg/g)
echo -e "$file" "$newfile" "\n_____________\n" >> rename_log.txt
echo -e "$file" "$newfile" "\n_____________\n"
mv "$file" "$newfile"
done

IFS=$SAVEIFS

cheers!
pcerf
 
Reply


 
Forum Jump


All times are GMT. The time now is 05:02.