rudamentary question

H

Hayden Smith

Greetings,
I'm looking to write a script to perform the functions listed as below, =
would anyone have any ideas as to how I might approach this situation:
1. I have a file called "David Slater - Pensive Moments.txt" which I =
wish to format to look like "David_Slater_-_Pensive_Moments.txt": =
Therefore translating all spaces for underscores.
2. I have a file called "[01] I am a fish.mp3" which I want to look like =
"01-I_Am_A_Fish.mp3" thus removing open brackets around numbers at the =
beginning, replacing the space between the number and name with a dash =
and performing the listed function as above.
3. The listed functions are required to be performed recursively across =
directory trees.
Any assistance people can provide would be most appreciated.
Regards,
Hayden Smith
----------
Hayden Smith
Email - (e-mail address removed)
website - http://www.AlternateProjects.com
Blog - http://SolaceOfTheMind.BlogSpot.com
Phone--
Australia:
Gold Coast - +617-56-678-016
Melbourne - +613-86-836-894
Sydney - +612-80-617-305
United States:
+1-310-405-6408 (with extension 61756678016)
United Kingdom:
+44-292-000-7380 (with extension 61756678016)
 
J

Justin Collins

Hayden said:
Greetings,
I'm looking to write a script to perform the functions listed as below, would anyone have any ideas as to how I might approach this situation:
1. I have a file called "David Slater - Pensive Moments.txt" which I wish to format to look like "David_Slater_-_Pensive_Moments.txt": Therefore translating all spaces for underscores.
2. I have a file called "[01] I am a fish.mp3" which I want to look like "01-I_Am_A_Fish.mp3" thus removing open brackets around numbers at the beginning, replacing the space between the number and name with a dash and performing the listed function as above.
3. The listed functions are required to be performed recursively across directory trees.
Any assistance people can provide would be most appreciated.
Regards,
Hayden Smith

Here are some places to start:

http://ruby-doc.org/core/classes/Dir.html#M002347
http://ruby-doc.org/core/classes/String.src/M000832.html
http://ruby-doc.org/core/classes/File.src/M002560.html

-Justin
 
B

badboy

Hayden said:
Greetings,
I'm looking to write a script to perform the functions listed as below, would anyone have any ideas as to how I might approach this situation:
1. I have a file called "David Slater - Pensive Moments.txt" which I wish to format to look like "David_Slater_-_Pensive_Moments.txt": Therefore translating all spaces for underscores.
2. I have a file called "[01] I am a fish.mp3" which I want to look like "01-I_Am_A_Fish.mp3" thus removing open brackets around numbers at the beginning, replacing the space between the number and name with a dash and performing the listed function as above.
3. The listed functions are required to be performed recursively across directory trees.
Any assistance people can provide would be most appreciated.
Regards,
Hayden Smith
----------
Hayden Smith
Email - (e-mail address removed)
website - http://www.AlternateProjects.com
Blog - http://SolaceOfTheMind.BlogSpot.com
Phone--
Australia:
Gold Coast - +617-56-678-016
Melbourne - +613-86-836-894
Sydney - +612-80-617-305
United States:
+1-310-405-6408 (with extension 61756678016)
United Kingdom:
+44-292-000-7380 (with extension 61756678016)
I would use a construct like this to replace the parts:
string.gsub(/^\[(\d+)\]\s?/,
'\1-').gsub(/\s+([-+\w])/){"_#{$1.upcase}"}.gsub(/^-/, '')
where string is your filename (works for both versions ;))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top