News:

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

Main Menu

A question on MasBasic

Started by clamicun, August 02, 2017, 10:00:00 AM

Previous topic - Next topic

clamicun

A question on MasmBasic

Hi jj,
if I use the GetFiles macro, I get the amount of files in eax and the full filenames in  Files$(ecx)...

Example...

GetFiles *.txt
mov counter,eax
xor ecx,ecx     ;Files$(0) 

.while counter !=0
push ecx           ;lstrcpy changes ecx
INVOKE lstrcpy,offset mybuffer,Files$(ecx)
;do something

;for example
;D:\temp\firstfolder\test1.txt

pop ecx
inc ecx
dec counter
.endw

Is there a possibility to isolate the path and the filename from Files$(ecx) ?
I would need to have the path: D:\temp\firstfolder\  and the filename: test1.txt


jj2007

@Hutch: Thanks for moving the thread :icon14:

Hi Clamicun,

Rinstr() can do what you need. Here is an example:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init

  PrintLine "GfNoPaths=0 (default):"
  GetFiles \Masm32\examples\exampl01\splash\*.asm|*.rc
  For_ ecx=0 To Min(9, eax-1)
                PrintLine Str$(GfSize(ecx)), Tb$, GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$, Files$(ecx)
  Next

  Let esi=Files$(0)             ; we pick a filestring, see below

  PrintLine CrLf$, "GfNoPaths=:"
  GfNoPaths=1                           ; do not include the paths
  GetFiles \Masm32\examples\exampl01\splash\*.asm|*.rc
  For_ ecx=0 To Min(9, eax-1)
                PrintLine Str$(GfSize(ecx)), Tb$, GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$, Files$(ecx)
  Next

  PrintLine CrLf$, "isolating path and file:", CrLf$, "full path: ", esi
  mov ecx, Rinstr(esi, "\")
  Let edi=Left$(esi, ecx-1)
  Let esi=Mid$(esi, ecx+1)
  PrintLine "the path:  ", edi
  Inkey "the file:  ", esi

EndOfCode

from MbGuide.rtf
        - you may use the following switches:
          GfNoPaths=            0/1     ; 0=include the path specified by user (default); 1=use file names only
          GfNoRecurse=          0/1     ; 0=include subfolders (default); 1=search only in current folder


Output:GfNoPaths=0 (default):
2104    08.06.1999  04:43:54    \Masm32\examples\exampl01\splash\filedlgs.asm
12771   08.06.1999  15:26:42    \Masm32\examples\exampl01\splash\splash.asm
...
GfNoPaths=:
2104    08.06.1999  04:43:54    filedlgs.asm
12771   08.06.1999  15:26:42    splash.asm
...
isolating path and file by hand:
full path: \Masm32\examples\exampl01\splash\filedlgs.asm
the path:  \Masm32\examples\exampl01\splash
the file:  filedlgs.asm


Question: What is your output when using, as in your code posted above, only GetFiles *.txt without a path?

Project attached. Tonight I will probably post a major MasmBasic update with some fixes for UAsm.

clamicun

Thank you,
that's what I needed.

Question: What is your output when using, as in your code posted above, only GetFiles *.txt without a path?
Returns all *.txt files in current directory.

clamicun

One more question...
Is it "normal"  if you use GetFiles or GetFolders on large folders eg. C:\  that the program  is kind of stalled for a while.  That is the minimize and maximize buttons don't react or even might bring down the program ?   

jj2007

Quote from: clamicun on August 03, 2017, 01:39:27 AM
Returns all *.txt files in current directory.

With or without path? Check CurDir$(0), it might do what you want.

Quote from: clamicun on August 03, 2017, 02:04:44 AM
One more question...
Is it "normal"  if you use GetFiles or GetFolders on large folders eg. C:\  that the program  is kind of stalled for a while.  That is the minimize and maximize buttons don't react or even might bring down the program ?

Yes, kind of. For performance reasons, there is no message loop that could slow down the file search. If you need responsiveness, do it in a separate thread and send a message to the main window when the thread is ready. Another option is GfCallback, but I haven't tested it.