Re: GetFilepart bug
Posted: Tue Nov 28, 2023 12:33 pm
You're right, that's what I meant.
http://www.purebasic.com
https://www.purebasic.fr/english/
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
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
Ok.... you are missing the pointLittle 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.
I know. And I took the liberty of confirming it.
You are right. I am missing your point, since you are artificially creating a problem that does not actually exist: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'.
First check the user input BEFORE automatically appending something to it. If it's empty, then it's an error.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"