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.
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.
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
WinAPI Shlwapi PathFindFileName (https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathfindfilenamea?redirectedfrom=MSDN) gives a pointer to filename part
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.
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.
Oh ok. Thank you.