jython snippet 01

List current directory content

from java.io import *
import os

# adapted from Java Almanac
currentDirectory = File(os.path.abspath(""))
li = dir.listFiles()

# pretty printing
for i in li: print i

dir.listFiles() will return an array (for the java engine).
Apparently you can treat an array as list, cool :lol:

p/s: yet to implement the filter as in the Java Almanac example.

A little googling results in (modified from Python Cookbook):

from import import io
class ff(io.FilenameFilter):
def accept(self, dir, name):
if name.lower()[-4:] == jar: return 1

L = io.File(os.path.abspath("")).list(ff())


Shahrin said...

JS nye version ada ???

:: unexistance :: said...

ha?? javascript nak read local file??