producing uncleanable garbage is no alternative...
Remove the extension part of a file.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Remove the extension part of a file.
@Wolf
producing uncleanable garbage is no alternative...
producing uncleanable garbage is no alternative...
oh... and have a nice day.
- Hroudtwolf
- Addict

- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
Re: Remove the extension part of a file.
Maybe you're right. I don't know if the stringmanager notes the memory-lenght of a string or it checks the null termination.
Therefore it could be unsafe.
Regards
Wolf
Therefore it could be unsafe.
Regards
Wolf
Re: Remove the extension part of a file.
Code: Select all
Procedure.s noext(tmp$)
pos.l = FindString(tmp$, ".", 1)
r$ = tmp$
Repeat
posseg = pos
If pos : r$ = Left(tmp$, pos-1) : EndIf
pos.l = FindString(tmp$, ".", pos + 1)
If pos< = posseg : Break : EndIf
ForEver
ProcedureReturn r$
EndProcedure
Debug noext("I.have.too.many.points.txt")
Debug noext("I have only one point.txt")
Debug noext("I haven't points")
PB 6.21 beta, PureVision User
Re: Remove the extension part of a file.
and how will your procedures handle ".htaccess"
?
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
Re: Remove the extension part of a file.
helpy wrote:and how will your procedures handle ".htaccess"?
Code: Select all
Procedure.s noext(tmp$)
pos.l = FindString(tmp$, ".", 1)
r$ = tmp$
Repeat
posseg = pos
If pos > 1 : r$ = Left(tmp$, pos-1) : EndIf
pos.l = FindString(tmp$, ".", pos + 1)
If pos< = posseg : Break : EndIf
ForEver
ProcedureReturn r$
EndProcedure
Debug noext(".I.have.too.many.points.txt")
Debug noext("I have only one point.txt")
Debug noext(".htaccess")
PB 6.21 beta, PureVision User
- Hroudtwolf
- Addict

- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
Re: Remove the extension part of a file.
ROFL.
Jetzt hast du uns bei den Eiern. ^^ (german metaphor. I don't know what it is in english.)
Very good objection!
Jetzt hast du uns bei den Eiern. ^^ (german metaphor. I don't know what it is in english.)
Very good objection!
- Joakim Christiansen
- Addict

- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
Re: Remove the extension part of a file.
Kaeru Gaman wrote:pwnedCode: Select all
filename$ = "Review 2009.09.23.doc" Debug StringField(filename$,1,".")
NOPE!Joakim Christiansen wrote:Can I get a cookie now?
This is a fun thread
I like logic, hence I dislike humans but love computers.
- utopiomania
- Addict

- Posts: 1655
- Joined: Tue May 10, 2005 10:00 pm
- Location: Norway
Re: Remove the extension part of a file.
Code: Select all
PathRemoveExtension_(@file)If so, thanks for the tip
Re: Remove the extension part of a file.
All these procedures are too big. Text manipulation such as this is what regular expressions where invented for. 
This is cross-platform:
This is cross-platform:
Code: Select all
Procedure.s RemoveExtension(Filename.s)
CreateRegularExpression(0, "(?<!\A)\.[\w]+\Z")
ProcedureReturn ReplaceRegularExpression(0, Filename, "")
EndProcedure
Debug RemoveExtension(".htaccess")
Debug RemoveExtension("Filename.exe")
Debug RemoveExtension("Filename.html")
Debug RemoveExtension("Filename.config")
Debug RemoveExtension("File.Name.jpeg")
Debug RemoveExtension("I have only one point.txt")
Debug RemoveExtension(".I.have.too.many.points.txt")
- Hroudtwolf
- Addict

- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
Re: Remove the extension part of a file.
It is just a short memory leak @Kale ^^
My recommendation.
Regards
Wolf
My recommendation.
Code: Select all
Procedure.s RemoveExtension(sFilename.s)
Static idRegEx.i
; Object recycling.
If Not (idRegEx)
idRegEx = CreateRegularExpression(#PB_Any , "(?<!\A)\.[\w]+\Z")
If Not (idRegEx)
ProcedureReturn sFilename
EndIf
EndIf
ProcedureReturn ReplaceRegularExpression(idRegEx, sFilename, "")
EndProcedure
Debug RemoveExtension(".htaccess")
Debug RemoveExtension("Filename.exe")
Debug RemoveExtension("Filename.html")
Debug RemoveExtension("Filename.config")
Debug RemoveExtension("File.Name.jpeg")
Debug RemoveExtension("I have only one point.txt")
Debug RemoveExtension(".I.have.too.many.points.txt")Wolf
Re: Remove the extension part of a file.
OK, I got a stupid question. Why can't you just rename the file to remove the extension?
Code: Select all
RenameFile("C:\test.txt", "C:\test")
works fine
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Remove the extension part of a file.
Kale wrote:All these procedures are too big. Text manipulation such as this is what regular expressions where invented for.

oh... and have a nice day.
Re: Remove the extension part of a file.
Apropos "too big": How big will be your resulting Exefile if you use reg. expressions instead of a small procedure which do the same job?Kale wrote:All these procedures are too big. Text manipulation such as this is what regular expressions where invented for.
PB 6.12 x64, OS: Win 11 24H2 x64, Desktopscaling: 150%, CPU: I7 12700 H, RAM: 32 GB, GPU: Intel(R) Iris(R) Xe Graphics | NVIDIA GeForce RTX 3070, User age in 2025: 57y
"Happiness is a pet." | "Never run a changing system!"
"Happiness is a pet." | "Never run a changing system!"
Re: Remove the extension part of a file.
@SFSxO1: You wouldn't know what to name it to until you had removed the extension.SFSxOI wrote:OK, I got a stupid question. Why can't you just rename the file to remove the extension?
Code: Select all
RenameFile("C:\test.txt", "C:\test") works fine
I believe the thread title was meant to read "Remove the extension part of a filename."
Re: Remove the extension part of a file.
Jealous?Kaeru Gaman wrote:xkcd.com imageKale wrote:All these procedures are too big. Text manipulation such as this is what regular expressions where invented for.
Explain. I don't understand why you've coded your procedure like that.Hroudtwolf wrote:It is just a short memory leak @Kale ^^


