1

I have some filepaths like this:

G:\folder1\folder2\folder3\folder4\folder5\fold2/197320-6-10-0.wav

How do I extract the last folder and file name like this:

fold2/197320-6-10-0.wav

Joe
  • 357
  • 2
  • 10
  • 32
  • The `/` is not a legal character in a Windows file name. See [HERE](https://stackoverflow.com/a/31976060/298607) – dawg Mar 20 '22 at 14:47

1 Answers1

1

Possible solution is to use split() function.

text_string = r'''G:\folder1\folder2\folder3\folder4\folder5\fold2/197320-6-10-0.wav'''

data = text_string.split("\\")[-1]

print(data)

Prints

fold2/197320-6-10-0.wav
gremur
  • 1,645
  • 2
  • 7
  • 20