# Show all files from a folder

**URL:** <https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386>\
**Category:** Ruby\
**Created:** [March 1, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386 "2006-03-01T20:43:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![misiek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@misiek](https://www.ruby-forum.com/u/misiek)\
**Post date:** [March 1, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386/1 "2006-03-01T20:43:49Z")

</div>

I can not find nothing about files in google,  
how to create delete, how to show all files from a folder

if you can redirect me to some web site I’d appreciate  
thanks

---

<div class="post-metadata">

**Author:** ![misiek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@misiek](https://www.ruby-forum.com/u/misiek)\
**Post date:** [March 1, 2006, 9:06pm UTC](https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386/2 "2006-03-01T21:06:04Z")

</div>

On Mar 1, 2006, at 1:43 PM, misiek wrote:

> I can not find nothing about files in google,  
> how to create

File.open(“my\_file.txt”, “w”) { |f| f.puts “A line in the file.” }

> delete

File.unlink “my\_file.txt”

> how to show all files from a folder

puts Dir[“path/to/dir/\*”]

> if you can redirect me to some web site I’d appreciate

Try browsing through the methods of File and Dir in the docs:

[http://www.ruby-doc.org/core/](http://www.ruby-doc.org/core/)

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![misiek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@misiek](https://www.ruby-forum.com/u/misiek)\
**Post date:** [March 1, 2006, 9:08pm UTC](https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386/3 "2006-03-01T21:08:46Z")

</div>

“misiek” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:du4tf9$8g5$removed\_email\_address@domain.invalid…

> I can not find nothing about files in google,  
> how to create delete, how to show all files from a folder
> 
> if you can redirect me to some web site I’d appreciate  
> thanks

Here’s the website I use:  
[http://www.rubycentral.com/ref/](http://www.rubycentral.com/ref/)

Check out Dir and File

Here’s some sample code I’ve been tinkering with that should get you  
started.

def findDirs (thisDir)  
Dir.entries(thisDir).each { |x|  
next if [“.” , “…”].include? x  
thisFile = File.join(thisDir,x)  
case File.ftype(thisFile)  
when “directory”  
puts "Found a directory: "+thisFile  
findDirs(thisFile)  
when “file”  
#puts "Found a file! "+File.join(thisDir, x)  
end  
}  
end

DirHelper.new.findDirs(ARGV[0])  
end

Jared  
[http://JaredRichardson.net](http://JaredRichardson.net)

---

<div class="post-metadata">

**Author:** ![misiek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@misiek](https://www.ruby-forum.com/u/misiek)\
**Post date:** [March 1, 2006, 9:53pm UTC](https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386/4 "2006-03-01T21:53:42Z")

</div>

thank you all of you for help 🙂

---

<div class="post-metadata">

**Author:** ![misiek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@misiek](https://www.ruby-forum.com/u/misiek)\
**Post date:** [March 1, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386/5 "2006-03-01T21:14:38Z")

</div>

Try Dir and File:

my\_dir = Dir[“C:/workspaces/Source/\*\*/\*.rb”] # collect all the  
ruby files recursively  
my\_dir.each do |filename|  
puts filename  
File.open(filename, “r”) do |f|  
puts f  
end  
end

Here’s a good place to start:

[http://ruby-doc.org/docs/ProgrammingRuby/](http://ruby-doc.org/docs/ProgrammingRuby/)

Look for Dir and File.

-Tom

---

<div class="post-metadata">

**Author:** ![misiek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@misiek](https://www.ruby-forum.com/u/misiek)\
**Post date:** [July 30, 2010, 3:14pm UTC](https://www.ruby-forum.com/t/show-all-files-from-a-folder/75386/6 "2010-07-30T15:14:26Z")

</div>

How can I display the content of a folder after some time of its  
creation, in order to see the newly added files?  
Any script with File.readlines? any help?

James G. wrote:

> On Mar 1, 2006, at 1:43 PM, misiek wrote:
> 
> > I can not find nothing about files in google,  
> > how to create
> 
> File.open(“my\_file.txt”, “w”) { |f| f.puts “A line in the file.” }
> 
> > delete
> 
> File.unlink “my\_file.txt”
> 
> > how to show all files from a folder
> 
> puts Dir[“path/to/dir/\*”]
> 
> > if you can redirect me to some web site I’d appreciate
> 
> Try browsing through the methods of File and Dir in the docs:
> 
> [RDoc Documentation](http://www.ruby-doc.org/core/)
> 
> Hope that helps.
> 
> James Edward G. II
