#!/usr/bin/tclsh
#
# This utility was created for the sole purpose of resolving a personal
# fuckup with CVS. All it does is recurse through a directory structure
# and remove any directories named "CVS". Why oh why is there not a way
# to do this with one or two normal shell commands?
#####

#####
# One directory at a time, please.
#####

if {$argc != 1} {
puts "\nUsage: rem-cvs \n"
exit 1
}

set dir [lindex $argv 0]

#####
# I said, one DIRECTORY at a time.
#####

if {[file isdirectory $dir] == 0} {

puts "\nUsage: rem-cvs \n"
exit 1
}

#####
# The heart of the beast. Go to the directory, remove any sub-directory named CVS,
# call yourself on every directory in the level you were called to clean.
# Note the "cd .." command. Oh golly is this one necessary... Don't forget it.
#####

proc kill_CVS {dir} {

cd $dir
file delete -force CVS
set contents [exec ls]

while {[regexp "(\[^\n\]+)(.*)" $contents match first rest]} {

set contents [string trimleft $rest]

if {[file isdirectory $first]} {

kill_CVS $first
cd ..
}

}
}

kill_CVS $dir