1

I am quiet new to ruby, rake, buildr and of course to FileUtils and FileList.

I have a directory structure like this:

+root
|-dir1
|+dir2
||-dir not to delete
||-dir3
|-dir4
…

After the clean, everything that should be left over is:

+root
|+dir2
||-dir not to delete

Right now I am trying that:

clean do
  FileList[_(:root) + "/**/*"]
    .exclude(_(:dir not to delete))
    .each do |file|
    puts file
  end
end

that »puts«

root/dir1
root/dir2
root/dir/dir3
root/dir4

But how can I now actually go over to delete everything accept the »dir not to delete« including inside its parent directory?

4

1 回答 1

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"]
于 2013-11-07T15:14:21.887 回答