How can I run a command on every WAV file in a folder?

0
4
Asked By MellowKite42 On

I'm using Composer's Desktop Project to edit audio files and want to apply the same command to a whole set of WAV files instead of entering it manually for each one. For a single file, the command is `distort average soundfile.wav soundfileoutput.wav`, where `distort average` is the command, followed by the input and output filenames. Is there a Terminal command or loop that can process every WAV file in the current folder without listing each filename in a script?

2 Answers

Answered By BrightPebble19 On

Another readable version is to remove the `.wav` extension first, then add the output suffix: `for input in *.wav; do base="${input%.wav}"; distort average "$input" "${base}output.wav"; done` Make sure the `distort` command is available in your PATH, or use its full path. This works in both Bash and Zsh, which are commonly available on macOS.

QuietHarbor6 -

If you save the loop in a script, you can start it with `#!/usr/bin/env bash` and make it executable with `chmod u+x scriptname`. Also be careful not to run it repeatedly in the same folder unless you change the file pattern, since generated output files may otherwise be processed again.

Answered By CedarVox7 On

A shell `for` loop can run the command once for every WAV file. From the folder containing the files, try: `for f in *.wav; do distort average "$f" "${f%.wav}output.wav"; done` This keeps the original filename and creates an output such as `soundfileoutput.wav`. The quotes also help protect filenames that contain spaces.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.