python - how can I get filenames without directory name -


how can list file names in directory without directory info in result? tried

for file in glob.glob(dir+filetype):     print file 

give me result /path_name/1.log,/path_name/2.log,.... need file name only: 1.log, 2.log, etc. not need directory info in result. there simple way rid of path info? don't want substr on result. thank you!

os.path.basename:

return base name of pathname path. second element of pair returned passing path function split(). note result of function different unix basename program; basename '/foo/bar/' returns 'bar', basename() function returns empty string ('').

so:

>>> os.path.basename('/path_name/1.log,/path_name/2.log') '2.log' 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -