Extract filename from path

后端 未结 8 667
梦谈多话
梦谈多话 2021-01-04 08:21

I need to extract the filename from a path (a string):

e.g., \"C:\\folder\\folder\\folder\\file.txt\" = \"file\" (or even \"file.txt\" to get me sta

8条回答
  •  北海茫月
    2021-01-04 08:32

    Thanks to kaveman for the help. Here is the full code I used to remove both the path and the extension (it is not full proof, does not take into consideration files that contain more than 2 decimals eg. *.tar.gz)

    sFullPath = "C:\dir\dir\dir\file.txt"   
    sFullFilename = Right(sFullPath, Len(sFullPath) - InStrRev(sFullPath, "\"))
    sFilename = Left(sFullFilename, (InStr(sFullFilename, ".") - 1))
    

    sFilename = "file"

提交回复
热议问题