Rev 33 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | ls | 1 | #! /usr/bin/env python3.1 |
2 | import sys |
||
3 | import os.path |
||
4 | |||
5 | # ============================================================================= |
||
6 | # Functions |
||
7 | # ============================================================================= |
||
8 | |||
9 | def Usage(mesg): |
||
10 | print ("Usage: " + progname + " directory") |
||
11 | print (mesg) |
||
12 | |||
13 | def traverse(directory): |
||
14 | curdir = os.getcwd() |
||
15 | os.chdir(directory) |
||
16 | curdir2 = os.getcwd() |
||
17 | files = os.listdir(curdir2) |
||
18 | for file in files: |
||
19 | pfile = curdir2 + "/" + file |
||
20 | if os.path.isdir(file) and not os.path.islink(file): |
||
21 | print (pfile) |
||
22 | traverse(file) |
||
23 | else: |
||
24 | if os.path.isfile(file) or os.path.islink(file): |
||
25 | print (pfile) |
||
26 | else: |
||
27 | print ("WARNING: Could not process file " + pfile) |
||
28 | os.chdir(curdir) |
||
29 | |||
30 | def start_traverse(directory): |
||
31 | print (directory) |
||
32 | traverse(directory) |
||
33 | |||
34 | # ============================================================================= |
||
35 | # MAIN |
||
36 | # ============================================================================= |
||
37 | |||
38 | progname = os.path.basename(sys.argv[0]) |
||
39 | if (len(sys.argv) == 2): |
||
40 | directory = sys.argv[1] |
||
41 | if os.path.isdir(directory): |
||
42 | start_traverse(directory) |
||
43 | else: |
||
44 | Usage("ERROR: No directory " + directory + " found") |
||
45 | else: |
||
46 | Usage("ERROR: 1 argument expected") |