0

Suppose I have a path like C:\\exportDir\\testing\\content\\catalog\\root\\shared\\First\\First_content\\Report1

How can I retreive the child filename in my case Report1 without using split by \\

kavya
  • 325
  • 2
  • 10

1 Answers1

0

Yes.

Use os.path.split()

Example:

import os 
  
# path 
path = '/home/User/Desktop/file.txt'
  
# Split the path in  
# head and tail pair 
head_tail = os.path.split(path) 
  
# print head and tail 
# of the specified path 
print("Head of '% s:'" % path, head_tail[0]) 
print("Tail of '% s:'" % path, head_tail[1], "\n") 
balderman
  • 22,927
  • 7
  • 34
  • 52
  • Using [`pathlib`](https://docs.python.org/3/library/pathlib.html) is much more sympathetic than `os.path` and is as easy as doing `pathlib.Path(path).name` – Tomerikoo Sep 14 '20 at 10:00