开发者

Detecting directories with "directory?" method

开发者 https://www.devze.com 2023-03-30 15:39 出处:网络
I want to detects directories im my computers.but when I write bel开发者_开发百科ow code , Ruby just give me \".\" and \"..\".

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消