#1 2024-11-25 15:57:41

vs
Member
Registered: 2019-10-21
Posts: 40

Using the FindFiles function

Hello!

Using the FindFiles function from mormot.core.search I have two questions.

1. How, without changing the source code, namely the constants faInvalidFile and faDirectoryMask, can I also get hidden files and files from hidden folders, as a result.
    For example, the *__history* directory from the folder with the source codes for Delphi IDE.

2. Is there any mechanism to determine that the function has stopped scanning the directory due to, for example, a broken VPN connection to the remote server. Now, in this case, the function returns the number of records that it successfully scanned before the connection was broken and without notification that the connection was lost during its execution.
   Probably it is worth analyzing GetLastError() <> ERROR_NO_MORE_FILES?
   https://learn.microsoft.com/en-us/windo … -directory

Maybe someone has encountered such cases and you already have solutions or solution options.

Thank you!

Last edited by vs (2024-11-25 15:58:08)

Offline

#2 2024-11-25 17:41:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,679
Website

Re: Using the FindFiles function

1. Please try
https://github.com/synopse/mORMot2/commit/8a5c8559

2. This would begin to make the function more complex than expected.
We rely on the FindFirst/FindNext/FindClose RTL functions for the search, which do not take into account how it stopped scanning.
There is no real guaranty that GetLastError() would indeed reflect the reason that FindFirst/FindNext failed on all targets.

Offline

#3 2024-11-25 22:56:27

vs
Member
Registered: 2019-10-21
Posts: 40

Re: Using the FindFiles function

Thanks, ab!
1. Partially. Hidden files in the list. But files from the hidden folders is out, unfortunately.

2. As an option, maybe after executing FindFiles try to check the last file in the list by the FileExists function. And if FileExists returns false, we can assume that the connection was broken.
Of course we should take the last file from the unsorted list and understand that there is a possibility that this last file could have been deleted during the time FindFiles ended and FileExists was called.
But at least it's something, than nothing )))

Last edited by vs (2024-11-25 23:04:18)

Offline

#4 2024-11-26 09:25:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,679
Website

Re: Using the FindFiles function

1. Please try
https://github.com/synopse/mORMot2/commit/d6ee09ca

2. It is really too much complex for this basic wrapper of FindFirst/FindNext/FindClose RTL functions.

Offline

#5 2024-11-26 17:15:19

vs
Member
Registered: 2019-10-21
Posts: 40

Re: Using the FindFiles function

1. Unfortunately, the result is the same as yesterday.
I guess that in the call

(FindFirst(fold + '*', faDirectory, F) = 0) then //line 1695 mormot.core.search 

it is necessary to set the faHidden parameter when ffoIncludeHiddenFiles in Options, something like this

(FindFirst(fold + '*', faDirectory or Integer(ffoIncludeHiddenFiles in Options) shl 1 {faHidden = $00000002}, F) = 0) then 

Of course, there is still the question of listing system files that are not currently on the list, but I am not sure if this is really necessary.


2. I probably expressed my thought incorrectly, it was not a request to include this check in the FindFiles function, but rather a question whether such an approach might work, and implement it in my extended function.

Thanks!

Offline

#6 2024-11-26 18:59:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,679
Website

Re: Using the FindFiles function

Offline

#7 2024-11-26 22:23:54

vs
Member
Registered: 2019-10-21
Posts: 40

Re: Using the FindFiles function

Thanks ab, as always!
With this commit, all hidden files and files from hidden subfolders are listed. Checked both Delphi and Lazarus on Windows.
Files with the system attribute are not in the list.

Last edited by vs (2024-11-26 23:27:54)

Offline

Board footer

Powered by FluxBB