如何获取当前读取文件的文件名?

file_name_1='Chapter10\cats.txt'
file_name_2='Chapter10\dogs.txt'

with open(file_name_1,'r') as file_object:
    title=file_object.name
    contents=file_object.read()
    title=file_object.
    petsname=contents.split()
    print(petsname)
    number=len(petsname)
    strname='There are '+str(number)+title+' whose name are:'
    for name in petsname:
        strname+=(name+',')
    print(strname[:-1]+'.')

代码如上,两个文件名分别是"cats"和“dogs”.如果用title=file_object.name只能输出相对路径即“Chapter10\cats.txt”。有没有什么办法只输出cats呢?
谢谢!

filename=r'E:\ebook\python\docs-pdf-2.7\c-api.pdf'
filename
'E:\ebook\python\docs-pdf-2.7\c-api.pdf'
fname=os.path.splitext(filename)
fname
('E:\ebook\python\docs-pdf-2.7\c-api', '.pdf')
os.path.split(fname[0])
('E:\ebook\python\docs-pdf-2.7', 'c-api')

使用的是Python

import os.path
s = '你上面的文件路径'
# 如果结果有误,是Unix和Window系统下路径分隔符不同导致的,可以加上
# s = s.replace('\', '/')
head = os.path.splitext(e)[0]
# file -> cats_or_dogs
file =  os.path.basename(head)