[Done]GetExtensionPart() of empty filename

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

[Done]GetExtensionPart() of empty filename

Post 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
ImageThe happiness is a road...
Not a destination
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: GetExtensionPart() of empty filename

Post 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'
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: GetExtensionPart() of empty filename

Post by Fred »

such files are usually hidden files name, which are not really extension only.
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: GetExtensionPart() of empty filename

Post by BarryG »

.htaccess is a classic example of a filename that is not an extension.
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: GetExtensionPart() of empty filename

Post 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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: GetExtensionPart() of empty filename

Post 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:
ImageThe happiness is a road...
Not a destination
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: GetExtensionPart() of empty filename

Post 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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: GetExtensionPart() of empty filename

Post 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") ; ""
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: GetExtensionPart() of empty filename

Post 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:
ImageThe happiness is a road...
Not a destination
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: GetExtensionPart() of empty filename

Post 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.
Axolotl
Addict
Addict
Posts: 802
Joined: Wed Dec 31, 2008 3:36 pm

Re: GetExtensionPart() of empty filename

Post 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." ) 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetExtensionPart() of empty filename

Post by mk-soft »

"\.tproject" is still a file without extension and not a file extension.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: GetExtensionPart() of empty filename

Post by Michael Vogel »

"The .htaccess file is always named .htaccess and does not include a filename before the dot"

https://fileinfo.com/extension/htaccess
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: GetExtensionPart() of empty filename

Post 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
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: GetExtensionPart() of empty filename

Post 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:
ImageThe happiness is a road...
Not a destination
Post Reply