Page 1 of 2

[Done]GetExtensionPart() of empty filename

Posted: Sun Jun 02, 2024 8:56 pm
by Kwai chang caine
Hello FRED

Code: Select all

Debug GetExtensionPart("X:\A\A\B\A\B\GTI\A\.tproject")
In my mind ...the return of debugger must be "tproject", but here it is empty with 5.73 and 6.10 :shock:
Is it a bug ?

Have a good day

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 9:06 am
by juergenkulow

Code: Select all

; Linux GetExtensionPart does not recognize file names ending with a backslash.
Filename$="X:\A\A\B\A\B\GTI\A\.tproject"
Debug "GetFilePart:"+GetFilePart(Filename$)
Debug "GetFilePart #PB_FileSystem_NoExtension:"+GetFilePart(Filename$,#PB_FileSystem_NoExtension)
Debug "GetExtensionPart:"+GetExtensionPart(Filename$)
Filename$="A\.svg"
Debug "GetExtensionPart:"+GetExtensionPart(Filename$)
; GetFilePart:X:\A\A\B\A\B\GTI\A\.tproject
; GetFilePart #PB_FileSystem_NoExtension:X:\A\A\B\A\B\GTI\A\
; GetExtensionPart:
; GetExtensionPart:

; kulow@kulow-G73Jw:~$ ls X*.tproject
; 'X:\A\A\B\A\B\GTI\A\.tproject'

; kulow@kulow-G73Jw:~$ ls A*.svg
; 'A\.svg'

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 9:11 am
by Fred
such files are usually hidden files name, which are not really extension only.

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 9:25 am
by BarryG
.htaccess is a classic example of a filename that is not an extension.

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 10:04 am
by Fred
We could add to GetExtensionPart() and GetFilePart() than a filename starting with a dot '.' (like .htaccess) is considered as a filename and not as an extension as these kind of name are very commonly used to design 'hidden' files

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 11:13 am
by Kwai chang caine
Hello FRED :D
Fred wrote: Mon Jun 03, 2024 9:11 am such files are usually hidden files name, which are not really extension only.
Yes you have right, but here it's not really the subject, hidden or not, it's a normal file, he have not name but have a real extension like others, then why it not treaty like the others ? :shock:
It's a "tProject" extension of TIZEN, so an extension not a name, and furthermore it's not an hidden file
I have talk about ".tproject", but beside there are a ".project" file not hidden too, and surely numerous files not hidden exist in all the applications of the world
Fred wrote:We could add to GetExtensionPart() and GetFilePart() than a filename starting with a dot '.' (like .htaccess) is considered as a filename and not as an extension as these kind of name are very commonly used to design 'hidden' files
We cannot change a rule, the fault of another parameter exist :shock: we'll never get out of this :|
As we would say in France "If my mother had them, it would be my father" or in more politically correct, "With several IF, we would remake the world" :wink:
It surprises me a little about you, because you are always implacably logical and rigorous. 8)

Perhaps the solution, is adding a style of parameter like #PB_FileSystem_StrictExtension for be sure a file "a.txt" give the same result than ".txt" :idea:
Instead of write this style of KCC cow pat :oops:

Code: Select all

Procedure.s GetExtensionPartEx(File.s)
 
 Name$ = GetFilePart(File)
 Extension$ = GetExtensionPart(File)
 
 If Trim(Extension$) = "" And Left(Name$, 1) = "."
  Extension$ = Mid(Name$, 2)
 EndIf
 
 ProcedureReturn Extension$
 
EndProcedure 
 
Debug GetExtensionPartEx("X:\A\A\B\A\B\GTI\A\.txt")
It's when even a problem when a function not return the same thing according to the attribute of an object, no ??? :shock:
Especially here, where it's more of a writing convention than anything else, so why bring in attributes that have nothing to see with the sauerkraut (French expression) :?:

This is precisely the strength of PB, the stability in the results of his functions 8)
And that...as someone we know well, would say :

Image

“Whatever it costs” :lol:

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 12:09 pm
by NicTheQuick
@Kwai chang caine: What translator are you using? It's not very good and you are a bit hard to understand. Maybe try DeepL or some AI driven stuff. That would be nice.

Back to topic:
dot-files are hidden files on Linux by convention, but not in Windows. A file with the name ".bashrc" does not have an extension. Its name is ".bashrc" and it is hidden. That's all. Furthermore file extensions does not mean a lot in the Linux world. There are some exceptions but in general Linux usually recognizes file types from the content of the file and not from the extension.f

With Windows this is different. Here file extensions are really important and files starting with a dot are not automatically hidden files. So does that mean we should change the behavior of GetExtensionPart() for Windows and Linux? I am not sure if this is a good idea. I remember that there were also issues creating such files in Windows using the Explorer: https://stackoverflow.com/questions/500 ... or-example

But what is a bit weird is this behavior:

Code: Select all

Debug GetFilePart(".bashrc.zip")# Outputs .bashrc.zip
I expected it to output just ".bashrc" here. Compare this to GetExtensionPart():

Code: Select all

Debug GetExtensionPart(".bashrc.zip")# Outputs .zip
As you can see both functions do not represent the same behavior.

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 12:12 pm
by BarryG
No need for Fred to change anything, IMO. The coder should just check the result:

Code: Select all

Procedure.s GetFileExtension(file$)
  ext$=GetExtensionPart(file$)
  If LCase(ext$)=LCase(file$)
    ext$=""
  EndIf
  ProcedureReturn ext$
EndProcedure

Debug GetFileExtension("X:\A\A\B\A\B\GTI\A\file.tproject") ; "tproject"
Debug GetFileExtension("X:\A\A\B\A\B\GTI\A\.tproject") ; ""
Debug GetFileExtension(".htaccess") ; ""

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 12:35 pm
by Kwai chang caine
@NicTheQuick
Yes i know it's complicated for FRED to according the three OS :|
But whatever anyone says, in WINDOWS a ".tproject", ".project" etc... is normal file, not hidden (although it doesn't matter) without name but with extension :wink:
It's the reason why, i talk about adding a parameter, perhaps only for WINDOWS (There are several parameters in PB who not works with all OS) :wink:

@BarryG
Your code not works for me :
Debug GetFileExtension("X:\A\A\B\A\B\GTI\A\.tproject") ; ""
return nothing, then ".tproject" is yet good an extension of IDE TIZEN project :wink:

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 4:34 pm
by Demivec
For windows, another thread to reference that is also not a bug: GetFilepart bug

However, it is acceptable to specify a period as the first character of a name. For example, ".temp".
Since a period is used as a separator between a filename and an extension, a period as the first character is part of the filename since there is no filename yet to mark a separation from for an extension to occur.

IMHO it is not a bug. The issue that NicTheQuick demonstrated with two functions, one returning the filename and the other returning the extension, both including the same portion of the name is a more important issue.

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 4:41 pm
by Axolotl
Hi KCC

maybe this will help.

Code: Select all

; Your Expectation: ".tproject" is an extension instead of an filename 
; 
Global TestFilename$ = "X:\A\A\B\A\B\GTI\A\.tproject" 

Procedure.s GetExtensionPartEx(FullPathName$) 
  Protected result$, e$, f$ 

  e$ = GetExtensionPart(FullPathName$) 
  f$ = GetFilePart(FullPathName$) 
  
  If e$ = "" And Left(f$, 1) = "." 
    If Right(f$, 1) = "." 
      result$ = e$ 
    Else 
      result$ = Mid(f$, 2) 
    EndIf 
  Else 
    result$ = e$ 
  EndIf 
  ProcedureReturn result$ 
EndProcedure

; the proof is in the pudding .... 
; 
Macro Test_FullPathName(Filename) 
  Debug "Filename = " + Filename
  Debug "  Ext    = " + GetExtensionPart(Filename) 
  Debug "  File   = " + GetFilePart(Filename) 
  Debug "  Ext.Ex = " + GetExtensionPartEx(Filename) 
  Debug "" 
EndMacro 

; the pudding .... 
; 
Test_FullPathName( "X:\A\A\B\A\B\GTI\A\.tproject" ) 
Test_FullPathName( "X:\A\A\B\A\B\GTI\A\a.tproject" ) 
Test_FullPathName( "X:\A\A\B\A\B\GTI\A\.tproject.a" ) 
Test_FullPathName( "X:\A\A\B\A\B\GTI\A\.tproject." ) 

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 5:23 pm
by mk-soft
"\.tproject" is still a file without extension and not a file extension.

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 5:26 pm
by Michael Vogel
"The .htaccess file is always named .htaccess and does not include a filename before the dot"

https://fileinfo.com/extension/htaccess

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 5:44 pm
by NicTheQuick
Michael Vogel wrote: Mon Jun 03, 2024 5:26 pm "The .htaccess file is always named .htaccess and does not include a filename before the dot"

https://fileinfo.com/extension/htaccess
I don't accept that as a definition. According to ChatGPT, there is no official convention as to whether dotfiles have an empty file name or whether everything is the file name.

There are better discussions about this topic to be found on Stackoverflow: https://stackoverflow.com/questions/321 ... -extension

Re: GetExtensionPart() of empty filename

Posted: Mon Jun 03, 2024 5:58 pm
by Kwai chang caine
@Axolotl
Thanks for your code 8)
Axolotl wrote:; the proof is in the pudding ....
:lol: :lol:
in fact... each of us, can see an extension or a name in the same word :cry:
It's the cherry on the cake :mrgreen: