Skip to content

Instantly share code, notes, and snippets.

@arlando
Created February 28, 2013 03:14
Show Gist options
  • Save arlando/5053894 to your computer and use it in GitHub Desktop.
Save arlando/5053894 to your computer and use it in GitHub Desktop.
Makes /main/foldersub/foldersub#.pde structure
#! /bin/bash
#This is a bash script used for creating a lot of folders to experiment in Processing!
#It asks for the input of the main folder... this folder will hold all of the Processing sub folders for example
#If mainfolder is called cupcake and you name the processing folders icings and you want three made
#the bash script will create:
# cupcake/icings0/icings0.pde
# cupcake/icings1/icings1.pde
# cupcake/icings2/icings2.pde
function isNull {
#if variable is null return true, else return false
if [ -z "$1" ]
then
return 0
else
return 1
fi
}
#superfolder
echo 'name of the main processing folders you wish to create...'
read MAINFOLDER
#check if null...
if isNull $MAINFOLDER; then
exec >&2; echo "error: Main Folder name was not set..."; exit 1
fi
#check if string...
if ! [[ "$MAINFOLDER" =~ ^[a-zA-Z][a-zA-Z0-9]+$ ]] ; then
exec >&2; echo "error: Main Folder was not a string"; exit 1
fi
#folder name
echo 'Please input the name of the Processing folders you wish to create...'
read FOLDERNAME
#check if null...
if isNull $FOLDERNAME; then
exec >&2; echo "error: Folder name was not set..."; exit 1
fi
#check if string...
if ! [[ "$FOLDERNAME" =~ ^[a-zA-Z]+$ ]] ; then
exec >&2; echo "error: Not a string"; exit 1
fi
#number of sub folders
echo 'Please input the number of sub folders you wish to create...'
read NUMBEROFFOLDERS
#$((NUMBEROFFOLDERS))
#check if null
if isNull $NUMBEROFFOLDERS; then
exec >&2; echo "error: Number of folders was not set..."; exit 1
fi
#not a number
if ! [[ "$NUMBEROFFOLDERS" != *[!0-9]* ]] ; then
exec >&2; echo "error: Not a number"; exit 1
fi
#if ! [[ "$NUMBEROFOLDERS" == ^0+$ ]] ; then
# exec >&2; echo "error: Number cannot just be zero"; exit 1
#fi
#create the number of sub folders
COUNTER=0
while [ $COUNTER -lt "$NUMBEROFFOLDERS" ]; do
#check if the directory exists
mkdir -p "$MAINFOLDER/$FOLDERNAME/$FOLDERNAME$COUNTER"
touch "$MAINFOLDER/$FOLDERNAME/$FOLDERNAME$COUNTER/$FOLDERNAME$COUNTER.pde"
echo "Created $MAINFOLDER/$FOLDERNAME/$FOLDERNAME$COUNTER/$FOLDERNAME$COUNTER.pde..."
let "COUNTER = COUNTER+1"
done
echo 'Complete!'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment