require 'find' require 'fileutils' def removeFiles( path, exts ) Find.find(path) do |f| if File.basename(f) == '.svn' FileUtils.remove_dir(f, true) Find.prune next end ext = File.extname(f) if exts.include?(ext) #File.delete(f) p f end end end

本文介绍了一个用Ruby编写的脚本,该脚本可以遍历指定路径下的所有文件,并删除特定扩展名的文件及.svn目录。通过使用Find和FileUtils模块,此脚本实现了高效的文件搜索与移除。
require 'find' require 'fileutils' def removeFiles( path, exts ) Find.find(path) do |f| if File.basename(f) == '.svn' FileUtils.remove_dir(f, true) Find.prune next end ext = File.extname(f) if exts.include?(ext) #File.delete(f) p f end end end

3351
816

被折叠的 条评论
为什么被折叠?