Yes there is. The Python path is even better.
There are three possibilities:
1) Like File.listFiles ():
Python has a os.listdir function (path). It works as a Java method.
2) pathname template extension with glob:
The glob module contains functions for listing files on a file system using a Unix shell template, for example.
files = glob.glob('/usr/joe/*.gif')
3) Moving a file using walk:
Really nice os.walk Python feature.
The walk method returns a generation function that recursively lists all directories and files below a given starting path.
Example:
import os from os.path import join for root, dirs, files in os.walk('/usr'): print "Current directory", root print "Sub directories", dirs print "Files", files
You can even delete directories from "dirs" on the fly so as not to reach this directory: if "joe" is in dirs: dirs.remove ("joe") so as not to go to directories called "joe".
listdir and walk are documented here . glob is documented here .
dmeister Sep 26 '08 at 17:30 2008-09-26 17:30
source share