0

I used the following code to read all files in a folder:

files_path = [os.path.abspath(x) for x in os.listdir()]
fnames_transfer = [x for x in files_path if x.endswith(".mkv")]

Now I need to extract the name of the file except its directory. For example fnames_transfer is E:\pythoncode\feature\1.mkv. I need to extract 1.mkv from this string. What should I do for this?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
david
  • 1,255
  • 4
  • 13
  • 26

1 Answers1

2

I used this os.path.basename(fnames_transfer[i] )and it works for me.

david
  • 1,255
  • 4
  • 13
  • 26