# traditional way
import os
path = "E:/facial_image_quality_assessment/pictures/126_1/*.jpg"
print(os.path.dirname(path))
# E:/facial_image_quality_assessment/pictures/126_1
print(os.path.basename(path))
#*.jpg
print(os.path.basename(os.path.dirname(path)))
# 126_1
# using pathlib
import pathlib
path = pathlib.PurePath("C:/folder1/folder2/filename.xml")
print(path.parent)
# C:\folder1\folder2
print(path.parent.name)
# folder2
如何利用python提取文件夹的名称
最新推荐文章于 2024-05-13 14:52:17 发布