How can you print the basenames of files by Python in the main folder and subfolders?
My attempt
#!/usr/bin/python
import os
import sys
def dir_basename (dir_name):
for dirpath, dirnames, filenames in os.walk(dir_name):
for fname in filenames:
print os.path.basename(fname) // Problem here!
if len(sys.argv) != 1:
u = "Usage: dir_basename <dir_name>\n"
sys.stderr.write(u)
sys.exit(1)
dir_basename ( sys.argv[1] )
1st problem solved with the off-by-one-error
2nd problem: The code gives me the output unsuccessfully
man.aux
about_8php.tex
refman.pdf
successful_notice.php
...
I expect to get as an output
aux
tex
pdf
php
...