File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ """
4+ file_lister
5+
6+ Write a program which prints the full path to all files in the current
7+ directory, one per line.
8+ """
9+
10+ import os
11+
12+ ## Two ways to do this:
13+
14+ ## One: get file names, and convert to absolute path:
15+
16+ print "listing using method one"
17+ for name in os .listdir (os .curdir ):
18+ print os .path .abspath (name )
19+
20+ # Note: os.curdir is "." on all sytems I knwo of...
21+ # so you could just do os.curdir(".")
22+ # Back in the days of the old MacOS -- it was different there.
23+
24+ ## Two: get the current dir path, then join that with each of the filenames
25+ curdir = os .getcwd ()
26+ print "listing using method two"
27+ for name in os .listdir (curdir ):
28+ print os .path .join (curdir , name )
29+
Original file line number Diff line number Diff line change 1- week 2: Chantal Huynh
1+ week 2: Chantal Huynh
22week 2: David Fugelso
33week 2: Ian M Davis
44week 2: Schuyler Alan Schwafel
You can’t perform that action at this time.
0 commit comments