2

I have a music player that ridiculously enough, refuses to play files according to the alphabetical and numerical order, but based upon the order in which they are copied to the audio player.

As such, I have for years copied files one at a time from my music folder to the folder in the music player to ensure they keep to their playlist order. Now that I have a few audio books, it would be a lot easier to automate the process explicitly with a bash script or any other solution.

Simply doing a Ctrl-A and Ctrl-V results in different files being copied and pasted at different times to the music folder. It's a problem if this results in the last chapter of an audio book being played before it should.

For example: c01.mp3, c02.mp3, c03.mp3 when copied to the audio player may be played in the order c03.mp3, c01.mp3, c02.mp3 instead of the correct numerical order.

My question is, what would be the best way to simplify the process?

6
  • As I can understand you would like to copy folder with all file in it and preserve the date of file, isn't it?
    – Lety
    Jul 14, 2014 at 21:42
  • The question is: how do you determine that order? If the filenames are in lexicographic order, it shouldn't be a problem: cp * /path/to/player/ should be enough. If they are not, do you have a playlist file, like an m3u?
    – muru
    Jul 14, 2014 at 21:52
  • I have added an example for clarity. While the lexicographic order would be the ideal outcome, I have had the files being played in the wrong order too often when doing a simple Ctrl-A Ctrl-V.
    – Rewarp
    Jul 14, 2014 at 22:06
  • @muru. Your solution was perfect. I didn't even consider the simple cp command because I thought that was the same thing being used in the GUI. If you write it in the answer section I will mark yours as the accepted answer. By the way, the audio player doesn't recognise any playlist files except its own proprietary format, so unfortunately, this is the only way to do it on Linux.
    – Rewarp
    Jul 14, 2014 at 22:26
  • @Rewarp I asked because we could parse the playlist to determine the order to copy. Anyway, I'll add the answer, and edit it if you have a playlist file.
    – muru
    Jul 14, 2014 at 22:28

2 Answers 2

4

If the files are in lexicographic order, the simplest way is:

cp * /path/to/player

If you use a loop-based approach, be sure to quote the variables ("$i") to handle filenames with spaces.

3

This should work; enter this through the command line.

for i in /directoryname/*.mp3; do cp "$i" /new_directory/; done

you would need to change 'mp3' to any different files you might have, and change the directory names to where your music is stored and to where you want the songs to go.

7
  • Your solution looks elegant. I am having problems though if the filename begins with numbers followed by the title. For example 01 - Teminus.mp3. What would be the solution?
    – Rewarp
    Jul 14, 2014 at 22:17
  • What kind of problems? Are you getting any sort of errors? The '*' symbol should be a 'catch-all', it should not matter what the file is named, as long as its a .mp3
    – user300217
    Jul 14, 2014 at 22:26
  • It's giving me errors like cp: target ‘Turbulence.mp3’ is not a directory
    – Rewarp
    Jul 14, 2014 at 22:28
  • I will just paste my complete command for i in /home/rewarp/Music/Learning\ to\ Manage\ Chaos/*.mp3; do cp $i /media/rewarp/EC95-4FBB/Music/Learning\ to\ Manage\ Chaos/$i; done
    – Rewarp
    Jul 14, 2014 at 22:41
  • 1
    Actually, this should work better; for i in /home/rewarp/Music/Learning\ to\ Manage\ Chaos/*.mp3; do cp "$i" /media/rewarp/EC95-4FBB/Music/Learning\ to\ Manage\ Chaos/; done. Just leaving out the last $i.
    – user300217
    Jul 14, 2014 at 23:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .