Pregunta

i have a rakefile with the following SRC = FileList['md/*.md'] but i want to exclude some files

I have tried

SRC = FileList['md/*.md'].exclude("md/header.md")
SRC = FileList['md/*.md'].exclude(/header/)
SRC = FileList['md/*.md'].exclude(/header.md$/)

But it doesn't work, always list me all files

a example:

in place of my rakefile.rb, I have a directory md with the following contents:

rakefile.rb
md/
  index.md
  example.md
  header.md

I want to list all without header.md

¿Fue útil?

Solución

This works fine for me:

p FileList['md/*.md']
#=> ["md/example.md", "md/header.md", "md/index.md"]

p FileList['md/*.md'].exclude("md/header.md")
#=> ["md/example.md", "md/index.md"]

p FileList['md/*.md'].exclude(/header/)
#=> ["md/example.md", "md/index.md"]

p FileList['md/*.md'].exclude(/header.md$/)
#=> ["md/example.md", "md/index.md"]

Otros consejos

Not sure what's going on. Perhaps it's the version of Rake and/or ruby that you're using?

I've tested your snippets with ruby-1.8.7 (rake 0.8.7 and rake 0.9.2.2) and with ruby-1.9.2 (rake 0.8.7 and rake 0.9.2.2). All four configurations give the expected output.

Code:

puts "no exculde:"
puts FileList['md/*.md']
puts '---'
puts "exclude('md/header.md'):"
puts FileList['md/*.md'].exclude('md/header.md')
puts '----'
puts "exclude(/header/):"
puts FileList['md/*.md'].exclude(/header/)
puts '----'
puts "exclude(/header.md$/):"
puts FileList['md/*.md'].exclude(/header.md$/)

Output:

no exculde:
md/example.md
md/header.md
md/index.md
---
exclude('md/header.md'):
md/example.md
md/index.md
----
exclude(/header/):
md/example.md
md/index.md
----
exclude(/header.md$/):
md/example.md
md/index.md
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top