For example,
1. I have a folder "Test" under "C:\\", and this folder has 4 files contains 1.txt, 2.txt, 3.txt, 4.txt
2. Open the command at "C:\\" using "SHIFT + RIGHT CLICK"
more at => Windows: http://darkkung-blog.blogspot.com/2010/10/open-command-window-at-current-path-in.html
Linux-Ubuntu: http://darkkung-blog.blogspot.com/2010/10/quick-open-teminal-in-ubuntu-by-using.html
3. Type "python" to open Python Interactive Shell
4. Use the following code to see your files in that directory.
import dircache flist = dircache.listdir("/Test/") print flist
This technique can be used with "os.path" to check the contents in that directory which one is file or directory such as "os.path.isdir()", "os.path.isfile()".
more at => http://docs.python.org/library/os.path.html#os.path.islink
p.s. This technique is operating system independent.
Credit: http://www.programmersheaven.com/mb/python/191482/191482/list-files-in-a-directory/
No comments:
Post a Comment