I'm trying to write a simple ruby script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). But I'm getting bogged down by trying to get the list of subdirectories
+2
A:
Dir.glob("**/")
will return an array of all paths underneath the current directory. From there you can filter the list and copy a file with File.copy(from, to)
Michael Sepcot
2009-04-28 23:40:45
+1
A:
If you mean to find all the immediate subdirectories (just one level below where you are), try this:
Dir.chdir("/some/path/you/want/to/check/below")
subdir_list=Dir["*"].reject{|o| not File.directory?(o)}
That is: change directory someplace, construct an array of files found there, reject those array elements that aren't directories, and return the resulting culled arrray.
glenra
2009-04-30 18:04:21
+5
A:
Assuming you only wanted the immediate subdirectories, you could use Dir['*/']
(which combines Micheal Sepcot's and glenra's answers).
Clay Bridges
2009-07-20 17:59:54
whats to "assume"? thats what he asked in the question! +1
Andrew Bullock
2010-04-08 08:00:41