我对ruby,rake,buildr以及FileUtils和FileList很安静。
我有一个像这样的目录结构:
+root
|-dir1
|+dir2
||-dir not to delete
||-dir3
|-dir4
…
干净后,应该留下的一切是:
+root
|+dir2
||-dir not to delete
现在我正在尝试:
clean do
FileList[_(:root) + "/**/*"]
.exclude(_(:dir not to delete))
.each do |file|
puts file
end
end
那个»把«
root/dir1
root/dir2
root/dir/dir3
root/dir4
但是我现在怎样才能实际删除所有接受“dir not to delete”包括在其父目录中?
答案 0 :(得分:3)
可能有更聪明的方法可以做到这一点,但你可以像这样减去相关的文件/目录:
我的配置目录中的所有文件:
FileList['config/**/**']
=> ["config/application.rb", "config/boot.rb", "config/compass.rb", "config/database.yml", "config/environment.rb", "config/environments", "config/environments/caching.rb", "config/environments/development.rb", "config/environments/production.rb", "config/environments/test.rb", "config/initializers", "config/initializers/formtastic.rb", "config/initializers/omniauth.rb", "config/initializers/secret_token.rb", "config/initializers/session_store.rb", "config/initializers/slim.rb", "config/initializers/typus.rb", "config/initializers/whitelabel.rb", "config/initializers/wrap_parameters.rb", "config/locales", "config/locales/de.base.yml", "config/locales/de.formtastic.yml", "config/locales/de.label.yml", "config/locales/de.yml", "config/locales/en.base.yml", "config/locales/en.formtastic.yml", "config/locales/en.label.yml", "config/locales/en.yml", "config/routes.rb", "config/typus", "config/typus/event.yml", "config/typus/highlight.yml", "config/typus/job.yml", "config/typus/location.yml", "config/typus/material.yml", "config/typus/topic.yml", "config/typus/user.yml", "config/whitelabel.yml"]
删除locales目录中的所有文件:
FileList['config/**/**'] - FileList['config/**/locales/**']
=> ["config/application.rb", "config/boot.rb", "config/compass.rb", "config/database.yml", "config/environment.rb", "config/environments", "config/environments/caching.rb", "config/environments/development.rb", "config/environments/production.rb", "config/environments/test.rb", "config/initializers", "config/initializers/formtastic.rb", "config/initializers/omniauth.rb", "config/initializers/secret_token.rb", "config/initializers/session_store.rb", "config/initializers/slim.rb", "config/initializers/typus.rb", "config/initializers/whitelabel.rb", "config/initializers/wrap_parameters.rb", "config/locales", "config/routes.rb", "config/typus", "config/typus/event.yml", "config/typus/highlight.yml", "config/typus/job.yml", "config/typus/location.yml", "config/typus/material.yml", "config/typus/topic.yml", "config/typus/user.yml", "config/whitelabel.yml"]