How do I extract a file/folder_name only from a path?

后端 未结 2 1340
醉话见心
醉话见心 2021-01-12 13:10

Unfortunately I suck at regexp. If I have a path like so:

/long/path/to/file, I just need to extact file.

If someone supplies

2条回答
  •  死守一世寂寞
    2021-01-12 13:53

    What about this?

    > path <- "/long/path/to/file"
    > require(stringr)
    > str_extract(path, "[^/]*$")
    [1] "file"
    

提交回复
热议问题