-2

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
  • 167
  • 13

1 Answers1

1

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
  • 10,166
  • 4
  • 29
  • 58