Page 1 of 1

[Implemented] Req: GetExtPart

Posted: Wed May 01, 2002 10:20 pm
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

Posted: Thu May 02, 2002 11:56 am
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

Posted: Thu May 02, 2002 3:56 pm
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

Posted: Thu May 02, 2002 4:54 pm
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

Posted: Thu May 02, 2002 10:31 pm
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