News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Get path without filename

Started by rc, November 01, 2019, 07:07:46 AM

Previous topic - Next topic

rc

Hello again,

i know this is probably an easy task for most of you here:

i want to cut off a file name from a path and concatenate a new file name to it.

Suppose i have a buffer containing a path: "c:/dev/test/task.asm" and i want to cut the file name off so that i just have the path. How am i suppose to do that?
After that i want to concatenate the path and a new file name (thats no problem):

mov pbuf, cat$(pbuf, pathBuf, "task2.asm")


But before i can concatene the new file name, i have to cut off the old file name first.
That file name however can vary in length, so i dont know the exact number of bytes to cut off.

As a test i have written the following code:

invoke SendMessage,hWin,WM_GETTEXTLENGTH,0,0
mov tl, eax
inc tl              ; 1 extra for zero terminator

invoke GetWindowText,hWin,ADDR buffer1,tl
invoke lstrcmp,ADDR buffer1,ADDR Untitled

.if eax == 0 ; eax is zero means strings are equal       
    fn MsgboxI,hWin,"Please save file first.!","AsmPad",MB_OK,500
.else
    fn MsgboxI,hWin,ADDR buffer1,"AsmPad",MB_OK,500
.endif


This just gets the window title which contains the current path to the saved file.
As a test, it launches a msgbox with the output of the current path or when untitled, a message that sais the user has to save the file first.

Here i want to cut off the filename from buffer1 and concatinate the new filename.

Vortex

Hello rc,

The library masm32.lib is offering the following path functions :

GetAppPath
NameFromPath
GetPathOnly


You can check \masm32\help\masmlib.chm for more information.

rc

So quick. This forum is awesome! Thank you. Works like a charm. :)
Really have to dig deeper into the help files!

For others, here is the working code:


invoke SendMessage,hWin,WM_GETTEXTLENGTH,0,0
mov tl, eax
inc tl              ; 1 extra for zero terminator

invoke GetWindowText,hWin,ADDR buffer1,tl
invoke lstrcmp,ADDR buffer1,ADDR Untitled

.if eax == 0 ; eax is zero means strings are equal       
    fn MsgboxI,hWin,"Please save file first.!","AsmPad",MB_OK,500
.else
    fn GetPathOnly, ADDR buffer1, ADDR buffer1
    fn MsgboxI,hWin,ADDR buffer1,"AsmPad",MB_OK,500
.endif



TimoVJL

WinAPI Shlwapi PathFindFileName gives a pointer to filename part
May the source be with you

rc

Short sidequestion: do i clear a buffer?
Lets say i have a temporary buffer: LOCAL tmpBuf[260]:BYTE
that i want to reuse? Then i have to clear it of course before reusing it.

TimoVJL

if you just copy a new content to it, no need to clear it first ?
zero first byte, if you add something to end of last string.
May the source be with you

rc