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?

1
  • 2
    Why are you using os.path.abspath() in the first place? Commented Sep 22, 2021 at 21:20

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.