Monday, 20 May 2013

How to list the files and folders completely by repeating a loop from the given path in ruby [closed]

How to list the files and folders completely by repeating a loop from the given path in ruby [closed]

$var=0
$var1=1
$directory=0
$path=gets.chomp
Dir["#$path"+"/"+"*"].each do |files|
if File.file?(files)
    $var+=1
    puts "#$var"+"."+files
elsif File.directory?(files)
        if Dir[files+"/"+"*"].empty?
        $var+=1
        puts "#$var"+"."+files
        elsif Dir[files+"/"+"*"].size!=0
        $var+=1   
        puts "#$var"+"."+files
        $directory=0
        Dir[files+"/"+"*"].each do|subdir|
        $directory+=1
        index="#$var."+"#$directory."
        puts index+subdir
            if File.directory?(subdir)
            $var1=1
            Dir[subdir+"/"+"*"].each do|childdir|
                puts index+"#$var1"+childdir   
                $var1+=1
            end
            end            
        end
    end
end
end
I have to repeat a loop if it is a directory and list all the content from it again if it has directory it must check if it is not empty the loop must list all the files in it and if it is not empty.

No comments:

Post a Comment