News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Appending File Extension

Started by Bieb, March 28, 2005, 11:18:35 PM

Previous topic - Next topic

Bieb

What's the best way to check and see if a string has a given extension (like .bmp) at the end of it and append that extension if it doesn't?

Faiseur

Hi,

It is simple if you use the API "PathAddExtension":


fn PathAddExtension, addr String, ".bmp"


Note:

a.if the String have an extension, no extension is added.

b. If the String no have extension, extension is added.

:-)


Add:
include shlwapi.inc
includelib shlwapi.lib


If you want to remove the extension (if there is...) use "PathRemoveExtension" (invoke PathRemoveExtension,addr String)





French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/

Bieb


Tedd

Hacky way:
- get string length
- check that last four characters = ".bmp"
- if not, append them :wink
No snowflake in an avalanche feels responsible.

sluggy

Quote from: Robert Bieber on March 28, 2005, 11:18:35 PM
What's the best way to check and see if a string has a given extension (like .bmp) at the end of it and append that extension if it doesn't?
Ahhhh, but what is an extension? "yourfile.bmp.bmp.bmp" is a perfectly legal name, as is "yourfile.areallylongextension", as is "afilenamewithnoextensionatall".

Sorry, couldn't resist going all Zen, "keepin' it real" as Ali G would say  :cheekygreen: :eek

Tedd

Quote from: sluggy on March 29, 2005, 11:10:09 AM
Quote from: Robert Bieber on March 28, 2005, 11:18:35 PM
What's the best way to check and see if a string has a given extension (like .bmp) at the end of it and append that extension if it doesn't?
Ahhhh, but what is an extension? "yourfile.bmp.bmp.bmp" is a perfectly legal name, as is "yourfile.areallylongextension", as is "afilenamewithnoextensionatall".

Sorry, couldn't resist going all Zen, "keepin' it real" as Ali G would say :cheekygreen: :eek

Aaah, but the question is, little grasshopper, whether the file has a particular extension - "blah.bmp.bmp.blah.bmp" is a perfectly legitimate filename, and it ends with ".bmp" which makes it a bmp file (as far as windows is concerned.)
No snowflake in an avalanche feels responsible.

P1

Not every file that ends in .bmp is a bmp format file. 

Regards,  P1  :8)

Tedd

Quote from: P1 on March 29, 2005, 03:05:33 PM
Not every file that ends in .bmp is a bmp format file.

That's why I said "(as far as windows is concerned)"  :P

Obviously you can't tell until you actually open it and check its format.
No snowflake in an avalanche feels responsible.

RuiLoureiro

Quote
Ahhhh, but what is an extension? "yourfile.bmp.bmp.bmp" is a perfectly legal name, as is "yourfile.areallylongextension", as is "afilenamewithnoextensionatall".

Sluggy, but he can test all .bmp begining at the end until the last «.». Why not ?

pbrennick

I have a telephone in the parlor and another in  the bedroom.  The one in the bedroom is an extension.

Paul

thomasantony

Hi,
  Since it is 4 chars get the last DWORD from the buffer i na register. Do a

cmp eax,'pmb.' ; .bmp in reverse due to intel byte ordering


Thomas
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

QvasiModo

There's also PathRemoveExtension and PathReplaceExtension to prevent duplicated extensions.