# Grade my test?

**URL:** <https://www.ruby-forum.com/t/grade-my-test/106995>\
**Category:** Ruby\
**Created:** [June 16, 2007, 7:12am UTC](https://www.ruby-forum.com/t/grade-my-test/106995 "2007-06-16T07:12:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jabowen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jabowen](https://www.ruby-forum.com/u/jabowen)\
**Post date:** [June 16, 2007, 7:12am UTC](https://www.ruby-forum.com/t/grade-my-test/106995/1 "2007-06-16T07:12:54Z")

</div>

I have directory of data files along with a few other types of files.  
The  
data file names start at 0000 and run to 3999. I have a program that  
creates an array for the data files without the non data files. This  
program works good but have I created the shortest way of doing the  
task?  
Thanks for grading my test. Jeff

#Puts the contents of the current directory into data\_files.  
dir\_file\_list = Dir.entries(".")  
data\_files = []

dir\_file\_list.each do|files|  
if files.to\_i \> 0 && files.to\_i \< 4000  
data\_files.push files  
end  
end

puts data\_files

---

<div class="post-metadata">

**Author:** ![jabowen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jabowen](https://www.ruby-forum.com/u/jabowen)\
**Post date:** [June 16, 2007, 11:48am UTC](https://www.ruby-forum.com/t/grade-my-test/106995/2 "2007-06-16T11:48:18Z")

</div>

On 6/16/07, jabowen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> dir\_file\_list.each do|files|  
> if files.to\_i \> 0 && files.to\_i \< 4000  
> data\_files.push files  
> end  
> end
> 
> puts data\_files

That would work just fine. Here’s another one:

data\_files = Dir.entries.select { |file| (1…4000).include? file.to\_i }

Be aware of how #to\_i works, though. This will grab a file named  
“24-7Project”, for example.

Todd

---

<div class="post-metadata">

**Author:** ![jabowen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jabowen](https://www.ruby-forum.com/u/jabowen)\
**Post date:** [June 16, 2007, 12:11pm UTC](https://www.ruby-forum.com/t/grade-my-test/106995/3 "2007-06-16T12:11:20Z")

</div>

On 6/16/07, jabowen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have directory of data files along with a few other types of files. The  
> data file names start at 0000 and run to 3999. I have a program that  
> creates an array for the data files without the non data files. This  
> program works good but have I created the shortest way of doing the task?  
> Thanks for grading my test. Jeff
> 
> #Puts the contents of the current directory into data\_files.  
> dir\_file\_list = Dir.entries(“.”)  
> data\_files = []
> 
> dir\_file\_list.each do|files|  
> if files.to\_i \> 0 && files.to\_i \< 4000  
> data\_files.push files  
> end  
> end
> 
> puts data\_files

Does it really work? What about file "0000’ ?  
The problem is that “a”.to\_i → 0  
I would go for

Dir[“[0-9]”\*4]

or  
Dir[“[0-3]” + “[0-9]”\*3]  
if necessary.

HTH  
Robert
