I want to detects directories im my computers.but when I write bel开发者_开发百科ow code , Ruby just give me "." and "..".
Dir.foreach("c:/windows") do |i|
puts i if File.directory(i)
end
please help me. thanks
Dir.foreach
returns only the filename (relative) , so it won't work. Build the absolute path or better try a simple:
Dir['c:/windows/*/']
Your code seems to work fine, except File.directory(i)
should be File.directory?(i)
Dir.foreach("/mnt/tmp") do |i|
puts i if File.directory?(i)
end
=>
.
..
majic
Dropbox
It is also the part of the directory. To move up folder. So need a conditions in the each file of the directory to remove those two files.
精彩评论