Skip to content

Commit d81261d

Browse files
PythonCHBAnastomose
authored andcommitted
added one more solution
1 parent 1fa519b commit d81261d

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

Solutions/Session04/file_lister.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+

lightning_schedule.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
week 2: Chantal Huynh
1+
week 2: Chantal Huynh
22
week 2: David Fugelso
33
week 2: Ian M Davis
44
week 2: Schuyler Alan Schwafel

0 commit comments

Comments
 (0)