Change a | delimited file : Utilities « File Directory « Ruby






Change a | delimited file



File.open("songdata") do |song_file| 
    songs = SongList.new 
        song_file.each do |line| 
        file, length, name, title = line.chomp.split(/\s*\|\s*/) 
        name.squeeze!(" ") 
        songs.append(Song.new(title, name, length)) 
    end 
    puts songs[1] 
end 

 








Related examples in the same category

1.delete a folder recursively
2.Find files
3.Delete with condition
4.Get free disk space under unix with df command
5.Get free disk space under windows with dir command
6.Call system function to delete a folder
7.Showing Line Numbers
8.Delete folder older than a certain time
9.Parse line: value|value