-1

How to get ONLY filename instead of full path?

For example:

path = /folder/file.txt

and i need to get:

filename = file.txt

How to do that?

Marek Grzyb
  • 177
  • 13

1 Answers1

2

You should use the os module:

import os
filename = os.path.basename(path)

For other path manipulations look here (for python 2.7) or here (for python 3)

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62