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!
return base name of pathname
path. second element of pair returned passingpathfunctionsplit(). note result of function different unixbasenameprogram;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
Post a Comment