On Thu, 25 Oct 2007 01:38:15 +0900, Bill K. wrote:
From: “Casimir P” [email protected]
All this just to find subdirectories and to list all the jpg files
inside!!
files = Dir[“img/**/*.jpg”]
Its too late for me!! EaArgv[0]!! Spaghetti! I am fallliiiiiiiiiing!!
“Procedural or death - RIP”
Only dozens of micro galleries remained after… What do you think? It
took me 17 hours to make. Or was it minutes? hehe 8)
#microgallery.rb
#command syntax: “ruby mgall.rb [directorypath]”
#Renders a html gallery from images inside the path passed as argument
#saves “mgallery.html” to current dir
def IndexImagesInDirs(pathstr)
#returns a hash with key equal to subdirectory name and
#value is an array with names of all images inside
#works only on dir path in pathstr, not recursive
require ‘find’
photodirs = Hash.new
photodirs[pathstr]=IndexImages(pathstr) #index images in root
Find.find(pathstr) do |item|
if FileTest.directory?(item)
if item != pathstr #not same dir, tho
tmp = IndexImages(item)
if (tmp.length > 0) #non-empty
photodirs[item]=tmp
end
end
end
end
return photodirs
end
def IndexImages(pathstr)
#Returns an array with filenames in pathstr
#that have extension equal to defined imageformats
imageformats = [“jpg”, “png”, “svg”, “gif”, “bmp”]
tmparr = Array.new
pathstr.each { |d|
Dir.entries(d).each { |filu|
nn = filu.to_s
ext = nn.downcase.split(“.”).last
imageformats.each { |frm|
if (ext == frm)
tmparr << filu
end
}
}
}
return tmparr
end
def ImageList(pathstr)
#point this to the directory with images in subdirectory-galleries
#makes a one page html list gallery from the images
#images in root are added as
dirs = IndexImagesInDirs(pathstr)
htmlpagestr = “”
dirs.each { |key, value|
value.each { |val|
val.insert(0, “/”)
htmlpagestr += '
image path: ’
htmlpagestr += key.to_s +
val.to_s
htmlpagestr += ‘
’
}
}
return htmlpagestr = htmlpagestr + “\n”
end
#start measuring time
time1 = Time.new.to_f
#make gallery
html = ImageList(ARGV[0])
#save to file
aFile = File.new(“mgallery.html”, “w”)
aFile << html
aFile.close
#stop measuring time
time1 = Time.new.to_f - time1
time1 *= 10
puts "total time required in time integer unit seconds " +
time1.to_i.to_s
#end microgallery