Extract file extension from file path

前端 未结 5 1359
太阳男子
太阳男子 2020-12-03 09:51

How can I extract the extension of a file given a file path as a character? I know I can do this via regular expression regexpr(\"\\\\.([[:alnum:]]+)$\", x), b

5条回答
  •  旧巷少年郎
    2020-12-03 10:08

    Let me extend a little bit great answer from https://stackoverflow.com/users/680068/zx8754

    Here is the simple code snippet

      # 1. Load library 'tools'
      library("tools")
    
      # 2. Get extension for file 'test.txt'
      file_ext("test.txt")
    

    The result should be 'txt'.

提交回复
热议问题