Remove path from filename

后端 未结 3 967
南笙
南笙 2020-12-16 09:22

I have trivial question.

I have string which contains a filename and it\'s path. How can i remove whole path? I have tried those:

line = \"/some/pat         


        
3条回答
  •  轮回少年
    2020-12-16 09:56

    The number is the index of the last slash in the string. If you want to get the file's base name, use filepath.Base:

    path := "/some/path/to/remove/file.name"
    file := filepath.Base(path)
    fmt.Println(file)
    

    Playground: http://play.golang.org/p/DzlCV-HC-r.

提交回复
热议问题