DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Remove CVS Directories With Ruby

08.07.2005
| 2935 views |
  • submit to reddit
        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

Snippets Manager replied on Mon, 2012/05/07 - 2:13pm

You can do the same with this shell script: find -d . -name 'CVS' -exec rm -rf '{}' \; -print