Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch nae change name 1

Status
Not open for further replies.

jstreich

Programmer
Apr 20, 2002
1,067
US
I have a program (lilypond) that outputs files with names like:

joy-parts.midi
joy-parts.ps
joy-parts.pdf
joy-parts-1.midi
joy-parts-1.ps
joy-parts-1.pdf
joy-parts-2.midi
...

What I would like to do is write a script to run after running lilypond that would rename (mv) them in mass to be a bit more meaningful:

joy-parts.midi => joy-score.midi
joy-parts.pdf => joy-score.pdf
joy-parts-1.midi=> joy-violin.midi

and so on.
Any ideas?

[plug=shameless]
[/plug]
 
How/where would you correlate between which "parts" name and which "meaningful" name?


HTH,

p5wizard
 
The the order the scores appear in the source file(s) feed to lilypond are in the file.

For this project:
- no number will be score
- 1 will be violin
- 2 will be flute
- 3 will be oboe
- 4 will be clarinet
- 5 will be "parts" which creates a pdf I use to "debug" may create a bunch of extra midi files that I don't care about and will delete later.

[plug=shameless]
[/plug]
 
Is this what you are looking for?

Code:
mv *parts.* *score.*
mv *parts-1.* *violin.*
mv *parts-2.* *flute.*
mv *parts-3.* *oboe.*
mv *parts-4.* *clarinet.*
mv *parts-5.* *debug.*
 
The stars expand in both the first and the second, part of those commands so it doesn't do what you think it does... Though I think it does in DOS. That isn't what I'm looking for.

[plug=shameless]
[/plug]
 
mind you this is untested:

Code:
name[0]=score
name[1]=violin
name[2]=flute
name[3]=oboe
name[4]=clarinet
name[5]=debug

for number in 0 1 2 3 4 5
do
 if ((number==0))
 then
  parts="parts"
 else
  parts="parts-${number}"
 fi
 for file in *${parts}.*
 do
  newname=$(echo ${file}|sed "s/${parts}/${name[number]}/")
  mv ${file} ${newname}
 done
done


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top