Page 1 of 1

Script to slightly alter folder/name.

Posted: July 11th, 2012, 12:14 am
by stergil
I'm struggling with automatically renaming a regular download.

Both the folder it gets moved to as well as the filename needs to use "&" instead of "and".

I'm using CentOS Linux and have a filter setup for the download already to trigger a script, I'm just not able to make the script operate as desired.

Any help is appreciated

Re: Script to slightly alter folder/name.

Posted: July 11th, 2012, 4:59 am
by sander
If you would post the script and tell what works and what not, maybe others can help.

Re: Script to slightly alter folder/name.

Posted: July 11th, 2012, 11:51 am
by exussum
rename -n-v 's/and/&/' *

should work

Re: Script to slightly alter folder/name.

Posted: July 11th, 2012, 10:09 pm
by stergil
exussum wrote:rename -n-v 's/and/&/' *

should work
Thanks for the quick response! It looks like that rename command will work real well on the file.

However, how do I get it moved to the proper folder?

So for example:

Code: Select all

/files/Some and Show/Season 2/Some.and.Show.S02E04.avi
needs to be moved and renamed to:

Code: Select all

/files/Some & Show/Season 2/Some.&.Show.S02E04.avi
Looks like I can easily get to the extract path with $1 & rename the file, but how do I figure out what season folder the file needs to be moved to?

Or am I over-thinking it, is there an easier way?

Re: Script to slightly alter folder/name.

Posted: July 12th, 2012, 6:00 am
by sander
If

Code: Select all

rename -n-v 's/and/&/' *
works, how about

Code: Select all

rename -n-v 's/and/&/' *
rename -n-v 's/and/&/' */*
rename -n-v 's/and/&/' */*/*
So: going three levels deep. I have not tested this, but it looks logical to me.