Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Remove CVS Directories with Ruby (See related posts)

Here's a simple Ruby script to remove CVS directories. Useful if you move a large codebase from one repository to another. To use it just go to the root directory where you want to start the deleting and run the script. The script will start in the current working directory and apply the removal recursively.

def deleteDir(dir)
    puts "cd #{dir}"
    Dir.chdir(dir)
    Dir.foreach(dir) do |file|
        if file != "." and file != ".."
            if File.directory?(file)
                deleteDir("#{dir}/#{file}")
            else
                puts "delete file #{file}"
                File.delete(file)
            end
        end
    end
    Dir.chdir("..")
    puts "delete directory #{dir}"
    Dir.delete(dir)
end

def processDir(dir)
    #puts "Processing directory #{dir}"
    Dir.chdir(dir)
    Dir.foreach(dir) do |file|
        if File.directory?(file)
            if file == "CVS"
                puts "Deleting directory #{dir}/#{file}"
                deleteDir("#{dir}/#{file}")
            elsif file != "." and file != ".."
                processDir("#{dir}/#{file}")
            end
        end
    end
    Dir.chdir("..")
end

puts "Working directory: #{Dir.pwd}"
processDir(Dir.pwd)

Comments on this post

whomwah posts on Dec 01, 2005 at 20:57
You can do the same with this shell script:

find -d . -name 'CVS' -exec rm -rf '{}' \; -print

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts