3

I'm trying to come up with a command that would run mp3gain FOLDER/SUBFOLDER/*.mp3 in each subfolder, but I'm having trouble understanding why this command doesn't work:

find . -type d -exec mp3gain \"{}\"/*.mp3 \;

When run, I get error Can't open "./FOLDER/SUBFOLDER"/*.mp3 for reading for each folder and subfolder.

If I run command manually with mp3gain "./FOLDER/SUBFOLDER"/*.mp3 it works. What's going wrong?

laite
  • 178
  • 1
  • 5

4 Answers4

3

If you have a fixed data structure like

folder1/subfolder1/
folder1/subfolder2/
folder2/subfolder1/
[...]

and using zsh or bash version >=4.0 you could try

mp3gain **/*.mp3

But to make sure check the output of

ls **/*.mp3 

before you are getting serious with mp3gain.

noqqe
  • 162
  • 8
  • The `**` syntax (which I love) is new in `bash` 4 or `zsh`. Some shells don't have it. And `ls **/*.mp3` is then enough (for those shells understanding `**`) – Basile Starynkevitch Jan 26 '13 at 11:55
1

When you run mp3gain "./FOLDER/SUBFOLDER"/*.mp3 from your shell, the *.mp3 is getting expanded by the shell before being passed to mp3gain. When find runs it, there is no shell involved, and the *.mp3 is getting passed literally to mp3gain. The latter has no idea how to deal with wildcards (because normally it doesn't have to).

NPE
  • 486,780
  • 108
  • 951
  • 1,012
0

Hmmm. Just tried this to test how the directory is parsed by replacing mp3gain with echo and it works:

find . -type d -exec echo {}\/\*.mp3 \;

Try running your version of the command but with echo to see the file output for yourself:

find . -type d -exec echo \"{}\"/*.mp3 \;

Seems the quotes get in the way in your original command.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
0

this works...

find /music -name *mp3 -exec mp3gain -r -k {} \;
Andrea
  • 11,801
  • 17
  • 65
  • 72
anon
  • 1