GetFilepart bug
-
- User
- Posts: 65
- Joined: Wed Jun 07, 2017 10:13 pm
GetFilepart bug
Debug Len(GetFilePart("C:\PureBasic\PB.exe"))
Debug Len(GetFilePart("C:\PureBasic\PB.exe",#PB_FileSystem_NoExtension))
Debug Len(GetFilePart("C:\PureBasic\.exe"))
Debug Len(GetFilePart("C:\PureBasic\.exe",#PB_FileSystem_NoExtension))
results in
6
2
4
4
should be
6
2
4
0
// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)
Debug Len(GetFilePart("C:\PureBasic\PB.exe",#PB_FileSystem_NoExtension))
Debug Len(GetFilePart("C:\PureBasic\.exe"))
Debug Len(GetFilePart("C:\PureBasic\.exe",#PB_FileSystem_NoExtension))
results in
6
2
4
4
should be
6
2
4
0
// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)
Re: GetFilepart bug
Not a bug, the prefix can't be empty. This file has no extension, the whole name is the prefix.
Last edited by jacdelad on Tue Nov 28, 2023 11:20 am, edited 1 time in total.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: GetFilepart bug
But there is no file part? And the manual doesn't say anything about a prefix requirement.
Code: Select all
file$=".exe" ; No file part specified (just an extension).
Debug GetFilePart(file$,#PB_FileSystem_NoExtension) ; ".exe" - why? This is not the file part.
Re: GetFilepart bug
Interesting question.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: GetFilepart bug
Workaround:
Code: Select all
Procedure.s GetFilePartEx(file$,flags)
file$=GetFilePart(file$)
If Left(file$,1)="." And CountString(file$,".")=1
file$=""
EndIf
ProcedureReturn GetFilePart(file$,flags)
EndProcedure
Debug GetFilePart("C:\PureBasic.exe",#PB_FileSystem_NoExtension) ; "PureBasic" - Right.
Debug GetFilePart("C:\.exe",#PB_FileSystem_NoExtension) ; ".exe" - Wrong.
Debug GetFilePartEx("C:\PureBasic.exe",#PB_FileSystem_NoExtension) ; "PureBasic" - Right.
Debug GetFilePartEx("C:\.exe",#PB_FileSystem_NoExtension) ; "" - Right.
Re: GetFilepart bug
".exe" is a valid filename, just like ".htaccess" they just don't have extensions.
[EDIT]
another example
Norm.
Code: Select all
Debug Len(GetFilePart("C:\PureBasic\.exe")) ; 4 character filename
Debug CheckFilename("C:\PureBasic\.exe") ; returns 0 if a valid filename
another example
Code: Select all
Debug GetFilePart("C:\.ForgotToCheckVarForFilename.lechat.thecat.diekatze.ilgatto",#PB_FileSystem_NoExtension)
Debug GetExtensionPart("C:\.ForgotToCheckVarForFilename.lechat.thecat.diekatze.ilgatto")
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
-
- User
- Posts: 65
- Joined: Wed Jun 07, 2017 10:13 pm
Re: GetFilepart bug
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"
Realy I don't care if ".lti" is a valid filename or not, since ".lti" is the extention the len(getfilepart(".lti",#PB_FileSystem_NoExtension)) should give 0
Since I know there IS an extention my workaround is simple
if Len(StringField(GetFilePart(filename),1,".")) = 0 --> no filename here

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"
Realy I don't care if ".lti" is a valid filename or not, since ".lti" is the extention the len(getfilepart(".lti",#PB_FileSystem_NoExtension)) should give 0
Since I know there IS an extention my workaround is simple
if Len(StringField(GetFilePart(filename),1,".")) = 0 --> no filename here

Re: GetFilepart bug
No bug in the original post.
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
Relevant quotes from the above link:
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
Relevant quotes from the above link:
Use a period to separate the base file name from the extension in the name of a directory or file.
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.However, it is acceptable to specify a period as the first character of a name. For example, ".temp".
-
- User
- Posts: 65
- Joined: Wed Jun 07, 2017 10:13 pm
Re: GetFilepart bug
@normeus
Unless your running a server, I think its not a good practice to start filnames with a dot, makes as you see things complicated.
As Einstein said "All solutions must be simple...." wouldend it be great, left from the dot is the filname, right from the dot is the extention
That may correct but then how do you know if you have "an empty filename with an extention" or "A weired legal filename with no extention" ??normeus wrote: Mon Nov 27, 2023 10:40 pm ".exe" is a valid filename, just like ".htaccess" they just don't have extensions.
Unless your running a server, I think its not a good practice to start filnames with a dot, makes as you see things complicated.
As Einstein said "All solutions must be simple...." wouldend it be great, left from the dot is the filname, right from the dot is the extention

-
- User
- Posts: 65
- Joined: Wed Jun 07, 2017 10:13 pm
Re: GetFilepart bug
So
I read all the replies, they are all correct.
There is no bug, for the system,
since filename ".lti" is a legal filename with no extention.
but from the users or programmers point of view the GetFilePart(filename,#PB_FileSystem_NoExtension) can NEVER work correctly .
since filename ".lti" can be
a legal filename with no extention
an empty (illegal) filename with an extention (as in my case)
Conclusion, nothing needs to be fixed, just work around it.
I read all the replies, they are all correct.
There is no bug, for the system,
since filename ".lti" is a legal filename with no extention.
but from the users or programmers point of view the GetFilePart(filename,#PB_FileSystem_NoExtension) can NEVER work correctly .
since filename ".lti" can be
a legal filename with no extention
an empty (illegal) filename with an extention (as in my case)
Conclusion, nothing needs to be fixed, just work around it.

Re: GetFilepart bug
In such a case, you can't ever know. It's a problem without a solution.williamvanhoecke wrote: Tue Nov 28, 2023 12:11 amhow do you know if you have "an empty filename with an extention" or "A weired legal filename with no extention" ??
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: GetFilepart bug
Since e.g. ".exe" and ".htaccess" are valid file names, 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.williamvanhoecke wrote: Tue Nov 28, 2023 12:11 am @normeus
That may correct but then how do you know if you have "an empty filename with an extention" or "A weired legal filename with no extention" ??normeus wrote: Mon Nov 27, 2023 10:40 pm ".exe" is a valid filename, just like ".htaccess" they just don't have extensions.
What is good practice and what is not is a different question. This is not a bug in PureBasic.williamvanhoecke wrote: Tue Nov 28, 2023 12:11 am Unless your running a server, I think its not a good practice to start filnames with a dot, makes as you see things complicated.
Last edited by Little John on Tue Nov 28, 2023 11:08 am, edited 1 time in total.
- NicTheQuick
- Addict
- Posts: 1504
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: GetFilepart bug
On Linux files starting with a dot are treated as hidden files. The name `.config` is basically a file named `config`, but hidden.
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.
Re: GetFilepart bug
So, after a long discussion we're back to what I said in my first post.
I guess GetFileExtension() just delivers the part after the last ".", regardless of what is in front of it.
I guess GetFileExtension() just delivers the part after the last ".", regardless of what is in front of it.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: GetFilepart bug
Yep.jacdelad wrote: Tue Nov 28, 2023 11:20 am So, after a long discussion we're back to what I said in my first post.

There is no GetFileExtension() function in PureBasic.jacdelad wrote: Tue Nov 28, 2023 11:20 am I guess GetFileExtension() just delivers the part after the last ".", regardless of what is in front of it.
You probably mean GetExtensionPart(). As far as I can see, its behaviour is consistent with GetFilePart() (PB 6.03 LTS on Windows).