Is there a command to copy music files in order?
I need to copy MP3s which are in folders by "Artist - Album" to a USB stick.
The MP3s must be copied in order, for example 01 Can You Feel It.mp3
should be copied before 02 Skyway.mp3
.
Is there a command to copy music files in order?
I need to copy MP3s which are in folders by "Artist - Album" to a USB stick.
The MP3s must be copied in order, for example 01 Can You Feel It.mp3
should be copied before 02 Skyway.mp3
.
You can't copy files in order with commandline or nautilus. But you can use midnight commander to copy some files in order. Install it on terminal with this command:
sudo apt-get install mc
If you can't find any ready-to-use software to do this, you can very easily write one.
In python, a script to recursively copy all files with there respective folders to a new folder in order, could look like this:
#/usr/bin/env python
import os
import sys
import shutil
try:
from_path = os.path.expanduser(os.path.expandvars(sys.argv[1]))
to_path = os.path.expanduser(os.path.expandvars(sys.argv[2]))
except:
print "Usage: copyinorder <from path> <to path>"
exit()
if not os.path.exists(to_path) or not os.path.exists(from_path):
exit("Error: both paths must exist.")
for dir_path, dir_names, file_names in os.walk(from_path):
if file_names:
new_dir_path = os.path.join(to_path, os.path.relpath(dir_path, from_path))
if not os.path.exists(new_dir_path):
os.makedirs(new_dir_path)
for name in sorted(file_names):
dest = os.path.join(new_dir_path, name)
src = os.path.join(dir_path, name)
shutil.copyfile(src, dest)
print "copied {0} \n to {1}".format(src, dest)
You could just save it somewhere (e.g. as "copyinoder"), make it executable (e.g. chmod +x copyinorder
) and run it like this:
copyinorder ~/Music/DavidBowie /media/N900/Music/
Note that in this case the "DavidBowie" folder will not be recreated.
Note also, that if the files are not as nicely named as in your example, then sorted
might not be the order you wanted.
This bit of code should do what you're looking for. Modify the sort
portion to alter the sorting behaviour to taste.
for i in "$(ls *.mp3 | sort)"; do cp "$i" "/destination/$i"; done
ETA: This might only work on a single directory at a time, but you can try ls -R
, though I don't know if that would copy recursively.