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

后端 未结 2 1295
醉话见心
醉话见心 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"
    
    0 讨论(0)
  • 2021-01-12 13:59

    If I understand correctly, you could use the basename function.

    f <- "/long/path/to/file"
    basename(f)
    # [1] "file"
    
    0 讨论(0)
提交回复
热议问题