#!/bin/sh # createfolders.sh # create a date-based folder hierarchy for an entire year # by Robert Daeley http://www.celsius1414.com/ # quick and dirty -- no error checking # ------------------------------------------------------------- # Array for number of days in each month # change the 28 manually for leap years numdays=( 0 31 28 31 30 31 30 31 31 30 31 30 31 ) # change targetpath to desired location targetpath=/Users/rdaeley/notebook/2006 # ------------------------------------------------------------- # first, a function to create a number of folders createfolders () { g=1 # this $1 refers to the value passed to this function while [ "$g" -le "$1" ] do # if the month or day is 1-9, we add a leading zero if [ "$g" -lt 10 ] then mkdir "0$g" else mkdir "$g" fi let "g += 1" done } # ------------------------------------------------------------- # now we get started cd "$targetpath" m=1 # We loop through the 12 months and create a folder for each # and, along the way, create the appropriate number of days. # First, the months... createfolders "12" # ...then we run through each month and create the day folders. while [ "$m" -le 12 ] do if [ "$m" -lt 10 ] then cd "$targetpath/0$m" else cd "$targetpath/$m" fi let "thismonth = ${numdays[$m]}" createfolders "$thismonth" let "m += 1" done exit 0