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
  • 14,486
  • 4
  • 43
  • 54
david
  • 961
  • 8
  • 22

1 Answers1

1

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

david
  • 961
  • 8
  • 22