programing

기본 이름이없는 파일 경로

projobs 2021. 1. 14. 08:02
반응형

기본 이름이없는 파일 경로


파일 basename없이 파일의 경로를 어떻게 얻을 수 있습니까?

/a/path/to/my/file.txt-> 같은 것/a/path/to/my/

성공하지 않고 .split () 시도


사용 os.path.dirname(filename).


당신은 할 수 있습니다 import os

>>> filepath
'/a/path/to/my/file.txt'
>>> os.path.dirname(filepath)
'/a/path/to/my'
>>> 

(dirname, filename) = os.path.split(path)

구독자 확인 os.path

os.path.dirname('/test/one')

참조 URL : https://stackoverflow.com/questions/11757520/path-to-a-file-without-basename

반응형