News:

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

Main Menu

Copy into Files$

Started by clamicun, September 03, 2017, 11:24:54 PM

Previous topic - Next topic

clamicun

jj bom dia,

store_file exists

mov hMem,alloc(5000000)
INVOKE CreateFile,offset store_file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 
mov filehandle,eax   
INVOKE GetFileSize,filehandle,0 
mov myfilesize,eax
INVOKE  ReadFile,filehandle,hMem,myfilesize,offset BytesRead,0   
INVOKE CloseHandle,filehandle

Is there a possibility to get the content of hMem into Files$ before free hMem   ?

clamicun

One more question...

Let esi = "C:\"
GetFolders esi   
mov dirs_found,eax
mov eax, ustr$(dirs_found)
Store offset store_file,Files$()

Is there a possibility to write eax=dirs_found somewhere into store_file ?
Preferably as first line. 

Excuse the many questions.

jj2007

Quote from: clamicun on September 03, 2017, 11:24:54 PMIs there a possibility to get the content of hMem into Files$ before free hMem  ?

The part before is easy:

include \masm32\MasmBasic\MasmBasic.inc         ; download
hMem   dd ?
store_file      db "stored_temp.txt", 0

  Init
  FileWrite offset store_file, "Hello"  ; make sure it exists
  Let hMem=FileRead$(offset store_file)
  Inkey "[", hMem, "]"
EndOfCode


But I assume you want to insert a line before the Store "MyFiles.txt", Files$(), right?

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  GetFolders "\Masm32\Examples"
  xchg eax, ecx                         ; save the count
  Insert Files$(0)
  Let Files$(0)=Str$("GetFolders() found %i folders in \Masm32\Examples", ecx)
  Store "ExampleFolders.txt", Files$()
  Inkey Str$("%i folders found. Wanna see them (y)?", ecx)
  If_ eax=="y" Then ShEx "ExampleFolders.txt"   ; opens Notepad etc
EndOfCode

clamicun

beautiful,
thanks a lot.

Let esi="MasmBasic is great"


clamicun

Think I was a bit too fast with "beautiful".

This is perfect.

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  GetFolders "C:\"
  xchg eax, ecx                         ; save the count
  Insert Files$(0)
  Let Files$(0)=Str$("%i", ecx)
  Store "Folders_C.txt", Files$()
  EndOfCode

But this is not what I meant.

hMem   dd ?
store_file      db "Folders_C.txt", 0
  Init
  ;FileWrite offset store_file, "Hello"  ; make sure it exists
  Let hMem=FileRead$(offset store_file)
  Inkey "[", hMem, "]"
EndOfCode

But...
Read the existing "Folders_C.txt and mov the content into Files$ for further use.
Something like...

mov hMem,alloc(5000000)
INVOKE CreateFile,offset store_file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 
mov filehandle,eax   
INVOKE GetFileSize,filehandle,0 
mov myfilesize,eax
INVOKE  ReadFile,filehandle,hMem,myfilesize,offset BytesRead,0   
INVOKE CloseHandle,filehandle

Now I have the storefile in hMem and want to get it into MasmBasics Files$ 


jj2007

As shown in my first reply, Let hMem=FileRead$(filename$) can load content. But filename$ seems to be a folder name here, so what content do you want to load?

Of course, you can do something like this (project attached):

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Dim content$()
  GetFiles \Masm32\Examples\*.asm|*.rc
  For_ ecx=0 To eax-1
        mov esi, Files$(ecx)
        Let content$(ecx)="Content of "+esi+cfm$(":\n")+FileRead$(esi)
  Next
  Insert content$(0)
  Let content$(0)=Str$("%i files found", ecx-1)
  Store "ContentExamplesAsmRC.txt", content$()
  Inkey content$(0), " - open as text(y)?"
  If_ eax=="y" Then Launch "\Masm32\MasmBasic\RichMasm.exe ContentExamplesAsmRC.txt#Content of"
EndOfCode


But this stores the contents of files, not folders (what is the content of folders??).

P.S.: Attention, the content$() array in the example above can quickly become really huge. The ..\examples asm and rc files are harmless, but C:\ cannot work...! If you plan to write gigabytes of content to disk, you need to wrtite sequentially.

clamicun

jj,
excuse me.
I seem to be quite ununderstandable.

store_file db "stored_Folders.txt",0
I have a file "stored_Folders.txt (it exists).

I open the file and read it into memory.

mov hMem,alloc(5000000)
INVOKE CreateFile,offset store_file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
mov filehandle,eax   
INVOKE GetFileSize,filehandle,0
mov myfilesize,eax
INVOKE  ReadFile,filehandle,hMem,myfilesize,offset BytesRead,0   
INVOKE CloseHandle,filehandle

Now I have the storefile in hMem.

This might be the same  in one line ?
Let esi=FileRead$("stored_Folders.txt")

FileRead$ stores the content where ?

How can I get the content of hMem into Files$ or some other array to use it ?

jj2007

Let esi means content goes to buffer to which esi points. Same for Let content$(ct)=whatever

clamicun

yes I know.

Let hMem=FileRead$(offset store_file)
or
Let esi=FileRead$(offset store_file)

hMem or esi have the adress of the string.

This is my one and only problem.
How can I get the content of hMem or esi back  into Files$ or some other array ! to use it like this ?

xor ecx,ecx
.repeat
INVOKE lstrcpy,offset somewhere,Files$(ecx) ; (or other array)   
inc ecx
do something
.until

StringToArray ??

If I am on your nerves leave it.
I 'll find out.

jj2007

Quote from: clamicun on September 04, 2017, 09:23:17 PMHow can I get the content of hMem or esi back  into Files$ or some other array ! to use it like this ?

You assign it directly to an array element:

Dim some$()
...
Let some$(123)=FileRead$(filename)  ; assign content
...
Print some$(123)  ; use it

clamicun

Well jj,
seems that we won't get together on this topic.

And anyway ... I will give up on MasmBasic - at least for a while.
The following prooves that I have't got any idea what it does.

This works....
include \masm32\MasmBasic\MasmBasic.inc
   
Init      

Dim A$()      ; first array
Dim B$()      ; second array
For_ ecx=0 To 9      ; ten loops
Let A$(ecx)=Str$("String A %i", ecx)      ; fill with more or less...
Let B$(ecx)=Str$("String B %i", ecx)           ; ... meaningful stuff
Next
ArrayMerge A$(), B$()                             ; A$(): 10xA, then 10xB; array B$() gets erased
For_ ecx=0 To 19                             ; twenty loops
PrintLine Str$("Element %_i\t", ecx), A$(ecx)
Next
Inkey
Exit debug   
end start       

This doesn't....
include \masm32\MasmBasic\MasmBasic.inc

.code
start:    

Dim A$()      ; first array
Dim B$()      ; second array
For_ ecx=0 To 9      ; ten loops
Let A$(ecx)=Str$("String A %i", ecx)      ; fill with more or less...
Let B$(ecx)=Str$("String B %i", ecx)           ; ... meaningful stuff
Next
ArrayMerge A$(), B$()                             ; A$(): 10xA, then 10xB; array B$() gets erased
For_ ecx=0 To 19                             ; twenty loops
PrintLine Str$("Element %_i\t", ecx), A$(ecx)
Next
Inkey
Exit debug   
end start     

Problemereignisname:   APPCRASH
  Anwendungsname:   jj2.exe
  Anwendungsversion:   0.0.0.0
  Anwendungszeitstempel:   59ae8f1c
  Fehlermodulname:   ntdll.dll
  Fehlermodulversion:   6.1.7601.23864
  Fehlermodulzeitstempel:   595fa4f4
  Ausnahmecode:   c0000005
  Ausnahmeoffset:   00052a0e
  Betriebsystemversion:   6.1.7601.2.1.0.256.1
  Gebietsschema-ID:   1031
  Zusatzinformation 1:   0a9e
  Zusatzinformation 2:   0a9e372d3b4ad19135b953a78882e789
  Zusatzinformation 3:   0a9e
  Zusatzinformation 4:   0a9e372d3b4ad19135b953a78882e789

Since 2 years I thought

.code
start:
end start

is the same as

Init
end start

jj2007

Quote from: clamicun on September 05, 2017, 10:12:07 PMSince 2 years I thought

.code
start:
end start

is the same as

Init
end start

Not exactly. The Init macro initialises several important things, inter alia it loads a global variable with the process heap required by the Dim statements. That's why Dim crashes without Init.

Rem - the Init macro inserts at least the following two lines:
.code
start: call MbBufferInit
- using Init is optional; it declares the code section, the start label, and preloads some strings (CrLf$, Tb$ etc.);
  however, the check for these preloaded strings will be performed in the first Print or Let statement, too.
- use Init tc [, con/key/box] to install a Structured Exception Handler with Try/Catch (\MasmBasic\details).


So this will work without crashes:.code
start: call MbBufferInit

clamicun

Many many thanks for all your patience

jj2007

No problem, such feedback is important for me. Still, I'd like to understand better what are your goals here...

clamicun

This is part of my "private" Searchprogram".
Better than all professioals. Ultrasearch, Wisesearch haha...

You pick the folder and the filetype
xor ecx,ecx
push ecx                                                                      ;lstrcpy changes ecx
INVOKE lstrcpy,offset path_file_type,Files$(ecx)              ;Verzeichnis 0
INVOKE lstrcat,offset path_file_type,offset slash              ;+ slash
INVOKE lstrcpy,offset current_path,offset path_file_type  ;Verzeichnis in current_path für LoadListView
INVOKE lstrcat,offset path_file_type,offset file_type         ;FileType *.xxx anhängen 

(I probably could do this directly with Files$ ?)

INVOKE FindFirstFile,offset path_file_type,offset wfd
"
"
Get the data you need (size, time, attribute, path) for LoadListView

GetFiles is usually faster, but GetFolders has the advantage that you have to do it only once, if you search for different filetypes in the same folder.

GetFiles you have to do every time for a different filetype
GetFiles C:\Windows\*.txt  GetFiles C:\Windows\*.exe ....

The problem always is C:\ ... can take a while.

So the idea is to store the folders of C:\ in the storefile  and read it into an array if you need it.
That is faster than to count the folders again.

Seems this does it.

Dim folderarray$()
Let esi=FileRead$("Folders_C.txt") 
StringToArray esi,folderarray$()

And do the same as above
INVOKE lstrcpy,offset path_file_type,folderarray$(ecx)
INVOKE lstrcat,offset path_file_type,offset slash             ;+ slash
INVOKE lstrcat,offset path_file_type,offset file_type         ;FileType *.xxx anhängen

Of course you have to renew the storefile once in a while.