Path to a file without basename

前端 未结 4 1070
轮回少年
轮回少年 2021-02-03 16:24

How can I get the path of a file without the file basename ?

Something like /a/path/to/my/file.txt --> /a/path/to/my/

Tried with .split

4条回答
  •  执笔经年
    2021-02-03 17:10

    You can import os

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

提交回复
热议问题