In PHP or other languages to get the content of a directory and all its subdirectories, you have to write some lines of code, but in Ruby it takes 2 lines:
require 'find'
Find.find('./') do |f| p f end
this will print the content of the current directory and all its subdirectories.
Or shorter, You can use the ’**’ notation :
p Dir['**/*.*']
How many lines will you write in PHP or in Java to get the same result?
require 'find'
Find.find('./') do |f| p f end
this will print the content of the current directory and all its subdirectories.
Or shorter, You can use the ’**’ notation :
p Dir['**/*.*']
How many lines will you write in PHP or in Java to get the same result?
13 Mar 2006 21:36:39
I was looking for a pretty way to do this. Neat code. Now, any good tricks for finding the available disk drives? I want something that basically shows me:
FileName, LastModified for *all* files on *all* disk drives on a Windows machine..
20 Apr 2006 14:02:53
you can save even _two more_ chars :-)
p Dir['**/*']
23 Feb 2007 18:06:10
That's not recursive. It's just one level deep. How do you do it for an entire directory tree from top to bottom?
15 Mar 2007 16:58:48
that is recursive.. the ** typeglob can go through all directories... to any depth
04 Apr 2007 00:42:04
I believe `ls -R .` works in PHP.
10 May 2007 21:07:30
what if I only need one level deep every time? How can I do it?
17 May 2007 23:25:34
# In Python you'd:
import os
print [f for f in os.walk('/')]
# Note: "print" is optional in this example, though I prefer the clarity of the keyword.
22 Nov 2007 22:04:00
`ls -R` works in ruby, too
10 Jan 2008 03:00:19
Not on a windows machine it doesn't!