当前位置: 软件>C/C++软件
编程语言 Alore
来源: http://www.oschina.net/p/alore
发布时间:2014-12-30
本文导语: Alore 是一个新的编程语言,有点类似 Python。 示例代码: -- Usage: nlargest.alo [DIR [N]] -- -- Find the N largest subdirectories of DIR (default to '.' and 10). import os def Main(args) var n = 10 var dir = '.' if args != [] dir = args[0] if args.length() > 1 ...
Alore 是一个新的编程语言,有点类似 Python。
示例代码:
-- Usage: nlargest.alo [DIR [N]] -- -- Find the N largest subdirectories of DIR (default to '.' and 10). import os def Main(args) var n = 10 var dir = '.' if args != [] dir = args[0] if args.length() > 1 n = Int(args[1]) end end LargestDirs(n, dir) end -- Display the n largest subdirectories of dir. def LargestDirs(n, dir) var a = [] DirSizes(dir, a) a = Reversed(Sort(a)) for size, d in a[:n] Print('{-8:} {}'.format(size div 1024, d)) end end -- Append to res a tuple (size, subdir) for each subdirectory of dir and return -- the total size of files in dir. def DirSizes(dir, res) var size = 0 for n in ListDir(dir) var p = Join(dir, n) if IsFile(p) size += Stat(p).size elif IsDir(p) and not IsLink(p) var s = DirSizes(p, res) res.append((s, NormPath(p))) size += s end end return size end
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。