GetFileExtension

Started by Vortex, July 14, 2007, 07:11:30 AM

Previous topic - Next topic

Vortex

Using Agner Fog's strlen routine, I modified the design of my procedure :

.386
.model flat,stdcall
option casemap:none

StrLen PROTO :DWORD

.code

GetFileExtension PROC _file:DWORD

invoke StrLen,_file
@@:
mov edx,_file
mov ecx,eax
xor eax,eax
sub ecx,1
@@:
cmp BYTE PTR [edx+ecx],'.'
je @f
sub ecx,1
jnz @b
ret
@@:
lea eax,[edx+ecx]
ret

GetFileExtension ENDP

END

[attachment deleted by admin]

jdoe

Sorry Vortex, I don't want to bother you but what about a path like this...

C:\TEST.1\TEST


::)


ramguru

I guess jdoe found the tricky path and extension (no extension) that will fail...but it's always hard to foresee every possible case

congrats Vortex...your last routine rocks the world: 13584 (your last) < 24732 (mine) < 32772 (your first) cycles | according to Agners tests

edit > I think in documentation there should be a note: "if file has no extension append dot (".") at the end anyway" that could solve the mentioned problem.

jdoe

Quote from: ramguru on July 24, 2007, 07:16:59 PM
...but it's always hard to foresee every possible case

In case of paths, there is no infinite possibilities. An extra compare for a backslash and the problem is solved.

:wink


Vortex

Jdoe,

There are also other possibilities :

C:\test1...test2..test3\test.4\test

I guess checking for the symbol \ can defeat those variations.

Grincheux

The simpliest way was to call InString :bdg :bdg
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz