dir ——size

$dirSize = 0
def process_files(aDir)
    totalBytes = 0
    Dir.foreach(aDir) do |f|
        myPath="#{aDir}\\#{f}"
        s = ""
        if File.directory?(myPath)
            if f!='.' and f!='..'
                bytesInDir = process_files(myPath)
                puts("<DIR>-->#{myPath} contains [#{bytesInDir}]B")
            end
        else
            fileSize=File.size(myPath)
               totalBytes += fileSize
            puts("#{myPath}:#{fileSize}B")
        end
    end
    $dirSize += totalBytes
    return totalBytes
end
process_files(".")
puts $dirSize


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章