Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6094715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:42:43+00:00 2026-05-23T12:42:43+00:00

i have a file that looks like this: TTITLE0=track name 1 TTITLE1=track name 2

  • 0

i have a file that looks like this:

TTITLE0=track name 1
TTITLE1=track name 2

and a directory that contains track01.cdda.wav.mp3 and track02.cdda.wav.mp3

i have the following code, which creates 2 different arrays, 1 with the track names and 1 with the track titles:

tracks = Dir.glob("*.mp3")

tracknames = Array.new
File.open('read').each do |line|
  if line =~ /TTITLE/
    tracknames << line.split("=")[1].strip!
  end
end

this gives me 2 arrays:

["track name 1", "track name 2"]

and

["track01.cdda.wav.mp3", "track02.cdda.wav.mp3"]

i would like to rename the files in the second array with the elements of the first array. so, "track01.cdda.wav.mp3" would become "track name 1.mp3".

here is what i have tried so far:

tracks.map {|track| File.rename("#{tracks}", "#{tracknames}.mp3") }

and i get the error:

No such file or directory - track01.cdda.wav.mp3track02.cdda.wav.mp3 or track name 1track name 2 (Errno::ENOENT)

i have to keep in mind that in the future there could be any number of elements in each array, but the numbers will be equal to each other.

any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:42:44+00:00Added an answer on May 23, 2026 at 12:42 pm

    Use Array#zip:

    tracks.zip(tracknames).each do |track, trackname|
      File.rename track, "#{trackname}.mp3"
    end
    

    Alternatively (less fun, but doesn’t create an intermediary array of arrays prior to enumeration):

    tracks.each_with_index do |track, i|
      File.rename track, "#{tracknames[i]}.mp3"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that looks kind of like this: junk stuff NAME Test
I have a .plist file that looks like this: <plist version=1.0> <array> <dict> <key>name</key>
I have a XML file that looks like this <Licence> <Name>Test company</Name> <Version>1.1.1.1</Version> <NumberOfServer>2</NumberOfServer>
I have a file that looks like this ID Name Car 1 Mike Honda
I have a file that contain lines that looks like this: >AF001546_1 [88 -
I have a file that contain list of numbers that looks like this: 10^-92
I have a text file that looks like this: value1 value2 value3 There are
I have a php file that looks like this: <?php include(config.php); // put the
I have an XML file that looks like this: <SiteMenuItems> <SiteMenuItem text=Home navigateurl=/Default.aspx tooltip=Return
I have a file that looks something like this: ABC DEF GHI I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.