Page 2 of 2

Re: GetFilepart bug

Posted: Tue Nov 28, 2023 12:33 pm
by jacdelad
You're right, that's what I meant.

{BUG Linux and Windows]Re: GetFilepart and GetExtensionPart bug

Posted: Tue Nov 28, 2023 12:37 pm
by juergenkulow
Linux:
Image

Code: Select all

-rw-rw-r--  1 kulow    kulow       147 Nov 27 13:30 ..png
-rw-rw-r--  1 kulow    kulow       147 Nov 27 13:30 .png
-rw-rw-r--  1 kulow    kulow       147 Nov 27 13:30 .Test.png

Code: Select all

; Extension of Filename /tmp/.png
Procedure.s FileDetail(FileName.s)
  ProcedureReturn FileName+" Size:"+FileSize(FileName)+" Path:"+GetPathPart(FileName)+
                  " Name:"+GetFilePart(FileName)+ 
                  " Name(NoExtension):"+GetFilePart(FileName,#PB_FileSystem_NoExtension)+
                  " Extension:"+ GetExtensionPart(FileName)
EndProcedure

Debug FileDetail("/tmp/.png")
Debug FileDetail("/tmp/..png")
Debug FileDetail("/tmp/.Test.png")

; /tmp/.png Size:147 Path:/tmp/ Name:.png Name(NoExtension):.png Extension:
;                                                           ^^^^           ^
; /tmp/..png Size:147 Path:/tmp/ Name:..png Name(NoExtension):. Extension:png
; /tmp/.Test.png Size:147 Path:/tmp/ Name:.Test.png Name(NoExtension):.Test Extension:png
Windows:
Image

Code: Select all

D:\tmp>dir /B
.Test.png
.png
..png

Code: Select all

; Extension of Filename d:\tmp\.png    
Procedure.s FileDetail(FileName.s)
  ProcedureReturn FileName+" Size:"+FileSize(FileName)+" Path:"+GetPathPart(FileName)+
                  " Name:"+GetFilePart(FileName)+ 
                  " Name(NoExtension):"+GetFilePart(FileName,#PB_FileSystem_NoExtension)+
                  " Extension:"+ GetExtensionPart(FileName)
EndProcedure

Debug FileDetail("d:\tmp\.png")
Debug FileDetail("d:\tmp\..png")
Debug FileDetail("d:\tmp\.Test.png") 

; d:\tmp\.png Size:147 Path:d:\tmp\ Name:.png Name(NoExtension):.png Extension:
;                                                               ^^^^           ^
; d:\tmp\..png Size:147 Path:d:\tmp\ Name:..png Name(NoExtension):. Extension:png
; d:\tmp\.Test.png Size:147 Path:d:\tmp\ Name:.Test.png Name(NoExtension):.Test Extension:png

Re: GetFilepart bug

Posted: Wed Nov 29, 2023 2:16 pm
by williamvanhoecke
Little John wrote: Tue Nov 28, 2023 11:03 am an empty filename with an extension simply does not exist. That's by definition, and it doesn't matter whether or not someone likes it.
Ok.... you are missing the point
I already agreed that this is not a PB bug.
I agree that a filename can start with a dot.
I also agree that 'empty filename with an extension' can not exist.
The point is..... how do you detect the difference between 'an ERRONEUS empty file with an extention' OR 'a weired LEGAL filename with no extention'.

Anyway, I do a workaround, so no worry.
Case closed

Re: GetFilepart bug

Posted: Wed Nov 29, 2023 2:26 pm
by Little John
williamvanhoecke wrote: Wed Nov 29, 2023 2:16 pm I already agreed that this is not a PB bug.
I know. And I took the liberty of confirming it.
williamvanhoecke wrote: Wed Nov 29, 2023 2:16 pm The point is..... how do you detect the difference between 'an ERRONEUS empty file with an extention' OR 'a weired LEGAL filename with no extention'.
You are right. I am missing your point, since you are artificially creating a problem that does not actually exist:
williamvanhoecke wrote: Mon Nov 27, 2023 11:31 pm I have this software where customer enter a raw 'name' for there file and the extention is then automatically added.
I then check is a 'name' was entered and if it is valid with CheckFilename(name).
So i get things like "C:\user\benjamin\customerfiles\.lti"
First check the user input BEFORE automatically appending something to it. If it's empty, then it's an error.