Author Topic: Newbie question: Process entire folder in Terminal  (Read 314 times)

uge

  • Jr. Member
  • **
  • Posts: 6
    • View Profile
Newbie question: Process entire folder in Terminal
« on: June 02, 2021, 08:02:02 AM »
Hello there,

I'm enjoying using the CDP in Terminal. I would like to know if is possible to use CDP commands with wildcards (*) in order to process entire folders.

Any help with this would be appreciated.

Thanks in advance,

Cheers,

Uge

rwdobson

  • Sr. Member
  • ****
  • Posts: 68
    • View Profile
Re: Newbie question: Process entire folder in Terminal
« Reply #1 on: June 03, 2021, 02:34:00 PM »
The idiomatic way to do this is to use the shell scripting facilities. It is a good idea to read up on shell commands (and practice a little before committing to anything serious). Simple commands can be done directly at the prompt, but most of the time you will want to create a text file for your script. Here is an example to copy files to a named subdirectory:

#!/bin/bash
# usage  copyfiles.sh outdir
# copies wave files in current directory to same names in directory outdir
# outdir will be created if not present
# copysfx must be in system PATH

if [ -z $1 ]; then
  echo "usage: ./copyfiles.sh outdir"
  echo "outdir will be created if it does not exist."
  echo
  exit
fi

if [ $1 == "." ]; then
echo "can't copy files into same directory!"
echo
exit
fi

if [ ! -d $1 ]; then
    mkdir $1
fi

for filename in *.wav
do
   copysfx $filename $1/$filename
done

uge

  • Jr. Member
  • **
  • Posts: 6
    • View Profile
Re: Newbie question: Process entire folder in Terminal
« Reply #2 on: June 04, 2021, 06:02:18 AM »
Thanks a lot,

I'll start experimenting with this. Yesterday I was reading a book about UNIX and I was trying some FOR loops with no luck. But this is the key of everything. I'll try this and practice with it.

Thanks again,

Uge