[Implemented] Req: GetExtPart

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] Req: GetExtPart

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

We have GetFilePart and GetPathPart, so please consider GetExtPart to retrieve
the file extension of a given string.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.
We have GetFilePart and GetPathPart, so please consider GetExtPart to retrieve
the file extension of a given string.


PB - Registered PureBasic Coder
Ohhhh dear!!

ext$=right(filename$,3) to get the last 3 characters

Mike

Tranquilizer/ Secretly!
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Sorry Tranquil but this doesn't work every time.

The reason is that if you have a file like:
MyBiggestFile.pb
you have only 2 chars in the extension.

Or if you have:
MyBiggestFile.manifest
you have more than 3.

You can't search for a dot with FindString and say: on the right side from the dot is the extension because you can have files like:
MyBiggestFile.3v1.exe


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Edited by - franco on 02 May 2002 17:02:30
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

Yep you are right. If you realy want to know what type of file you get, read the file header and examine it to find out the real file type. :)

Mike

Tranquilizer/ Secretly!
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> ext$=right(filename$,3) to get the last 3 characters

As Franco said, what if the extension is not 3 chars, or the string to be
tested has a closing quote? For example, what if filename$ contained:

PureBasicSource.pb
"C:\OtherExample.txt"
WebDocument.shmtl
Dot.In.FileName.zip

Anyway, I have posted an working tip in the Tricks 'N' Tips section, until
Fred can add such a command, if he agrees to one.


PB - Registered PureBasic Coder

Edited by - PB on 02 May 2002 23:35:21
Post Reply