I am using mp3splt to split all the .mp3 files under a directory, including subdirectories, into 30 minute slices.

find -name *.mp3 -print0 | xargs -0  mp3splt -t 30.00 -o @f_@m@s

What is the best way to delete the original file after the splitting is complete?

link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

Create and chmod +x the following script, mp3splt_and_delete.sh:

#!/usr/bin/env bash
mp3splt -t 30.00 -o @f_@m@s "$@"
rm "$@"

Then you can run

find -name *.mp3 -print0 | xargs -0 /path/to/mp3splt_and_delete.sh

You could also try something like the following, but it'll create separate invocations of mp3splt:

find -name "*.mp3" -exec mp3split -t 30.00 -o @f_@m@s {} \; -a -delete

This requires mp3split to return a exit code of 0, indicating success.

link|improve this answer
The first solution works just fine for me. I traversing the subdirectories is a requirement. – Garrett Rowe Dec 2 '11 at 7:35
feedback

As a quick fix try:

#!/bin/bash
for file in *.mp3
do
mp3splt -t 30.0.0 -o @f_@m@s "$file"
rm -f "$file"
done
link|improve this answer
@DanielBeck I have updated the answer. I think the added quotes do the trick. – Sachin Divekar Dec 2 '11 at 6:36
I think so too, yes. Now you don't handle files in subdirectories, which are also returned by find without -maxdepth. Can't say if it's an issue for the user though. – Daniel Beck Dec 2 '11 at 6:38
@DanielBeck that's why I have added quick fix. We can add many more sophistications. And user himself have find without maxdepth. – Sachin Divekar Dec 2 '11 at 6:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.