jason7
1
hi:
I have some files like this
folder1/recording1.mp3
folder1/docs/budget.doc
folder2/others/misc.mp3
folder3/others/notes.doc
all this folders and files are under the mp3 folder.
I would like to move just the mp3s to another folder but retain the subdir structure i have.
So if a mp3 was under folder2/others
then it is moved to
newmp3s/folder2/others
All the .doc files should remain intact and not moved.
Thanks in advance.
pludi
2
find folder1/ folder2/ -name '*.mp3' -print | while read file
do
echo mkdir -p $( dirname $file )
echo mv $file newdir/$( dirname $file )
done
If it looks like it should (eg no unexpected stuff), remove the echos.
jason7
3
when I use it with echos it looks like it should work. mkdir commands are duplicated though.
When I run it without echos I get a "No such file or directory" message.
It finds the files and everything but it doesnt create the folders I guess.
pludi
4
Sorry, my bad. Missed to include the new directory in the mkdir (red part)
find folder1/ folder2/ -name '*.mp3' -print | while read file
do
echo mkdir -p newdir/$( dirname $file )
echo mv $file newdir/$( dirname $file )
done