I want to write a program that get from user a path and then go to that directory and all of subdirectories recurcively and collect all txt files. but “.” and “..” bother me when I am iterating directories recurcively. please help me to eradicating this problem.
this is my code :
def detect_files(path)
Dir.foreach(path) do |i|
if (i != "." or i !="..")
if (File.directory?(i))
detect_files(i)
end
if (i.reverse.start_with?("txt."))
@files[i]=[]
end
end
end
end
The condition should be :
i="."theni != "."will be false making the condition false, and"."will not be processedi=".."theni != "."will be true buti != ".."will be false, making the condition false and".."will not be processed.ihas any other values, then both side ofandwill be true and the body ofifwill be executed.