B4J Question FileBaseName & FileExtension

Walt

Member
FileBaseName and FileExtension, found in the jMMTools library are just what I needed.
But, I'd like to know if there are any other slick ways the get the name and extension out of a file?
 

stevel05

Expert
Licensed User
Longtime User
Try:
B4X:
    Dim FullFilePath As String = "C:/users/file.ext"
    Dim FileName As String = File.GetName(FullFilePath)
    Dim Pos As Int = FileName.LastIndexOf(".")
    Dim FileBase As String =  FileName.SubString2(0,Pos)
    Dim FileExtn As String = FileName.SubString(Pos)
    Log(FileBase)
    Log(FileExtn)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
As Erel wrote, files not necessarily have extension.

Some files have more than one period. Example: project.b4j.meta

Some files have period but behind it I don't consider as extension. Example, .gitignore I consider the filename is the full name including the period.

We can use the last index but then file like project.b4j.meta should be having project as file name and .b4j.meta as extension or is it consider project.meta is actually the file name?
For me the former is more accurate.

This is just my thought.
 
Upvote 0
Top