Score:1

Directory names with blanks - recursive file check

um flag

To check the play length of audio files, I'm using the following script:

#!/bin/bash
for dir in $(find . -type d); do
cd $dir

for file in *.ogg *.wav *.mp3
do
  duration=$(ffprobe "$file" 2>&1 | awk '/Duration/ { print $2 }')
  echo -e "$duration\t$file"
done | sort -n

cd - > /dev/null
done

Where the directories being read recursively contain no spaces in the names, this works fine.

When there is a space in the directory name, the first and second parts become separated in the $dir variable, so...

  • dir 1

becomes

  • dir

and

  • 1

Unfortunately my scripting knowledge is lacking, so I'd be hugely grateful if someone could point me in the right direction so that the full directory name is passed into the variable.

Many thanks,

James.

hr flag
Have a look here: [Why is looping over find's output bad practice?](https://unix.stackexchange.com/questions/321697/why-is-looping-over-finds-output-bad-practice) - simplest would probably be to replace the outer for loop with a null-delimited while loop
Score:1
ua flag

Instead of

for dir in $(find . -type d); do
cd $dir

use

find . -type d -print0 | while read -r -d $'\0' dir; do
cd "$dir"
JamesB avatar
um flag
Thank you! :) :)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.