Python, add trailing slash to directory string, os independently

后端 未结 4 903
长情又很酷
长情又很酷 2021-01-30 10:02

How can I add a trailing slash (/ for *nix, \\ for win32) to a directory string, if the tailing slash is not already there? Thanks!

4条回答
  •  -上瘾入骨i
    2021-01-30 10:42

    You could use something like this:

    os.path.normcase(path)
        Normalize the case of a pathname. On Unix and Mac OS X, this returns the path unchanged; on case-insensitive filesystems, it converts the path to lowercase. On Windows, it also converts forward slashes to backward slashes.
    

    Else you could look for something else on this page

提交回复
热议问题