gpt4 book ai didi

ruby - Rake FileList——清理目录,排除子目录

转载 作者:太空宇宙 更新时间:2023-11-03 18:20:09 25 4
gpt4 key购买 nike

我对 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« 的内容,包括其父目录中的内容?

最佳答案

可能有更聪明的方法来做到这一点,但您可以像这样减去相关文件/目录:

我的配置目录中的所有文件:

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"]

关于ruby - Rake FileList——清理目录,排除子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19837289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com