The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: DerCoder on December 11, 2011, 08:50:57 PM

Title: BaseName
Post by: DerCoder on December 11, 2011, 08:50:57 PM
Hey guyz,

is there a possibility to get a paths basename. For example:
.DATA
    szPath DB "C:\folder1\folder2\file.ext", 0
...
.CODE
    invoke BaseName, ADDR szPath

would store "file.ext" in eax register.

Maybe there is a macro?

Greetz DerCoder
Title: Re: BaseName
Post by: Gunner on December 11, 2011, 09:07:50 PM
Open \masm32\help\masmlib.chm there is a function called NameFromPath
Title: Re: BaseName
Post by: DerCoder on December 11, 2011, 09:13:58 PM
WOOW Big thx for 1) the fast reply and 2) for the nice answer =)
Title: Re: BaseName
Post by: jj2007 on December 11, 2011, 10:32:13 PM
Another option ;-)

include \masm32\MasmBasic\MasmBasic.inc   ; Download (http://www.masm32.com/board/index.php?topic=12460)
   Init
   Inkey Mid$(CL$(), Rinstr(CL$(), "\")+1)   ; CL$() means CommandLine$
   Exit
end start
Title: Re: BaseName
Post by: ragdog on December 12, 2011, 03:00:01 PM
Or use from Shlwapi.lib PathFindFileName

PTSTR PathFindFileName(
  __in  PTSTR pPath
);

Invoke PathFindFileName,addr szPath

And other Path function in Shlwapi can your read here.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773559%28v=VS.85%29.aspx

Or use my old code

invoke  lstrlen,addr szPath
    lea  esi,szPath
   add  eax,esi
.while BYTE PTR [eax] != '\'
        dec  eax
.endw
inc  eax


Greets,