View Issue Details

IDProjectCategoryView StatusLast Update
0034607LazarusFCLpublic2018-12-02 11:01
ReporterMiguel Oliveira Assigned ToBart Broersma  
Status closedResolutionfixed 
Target Version2.2Fixed in Version2.2 
Summary0034607: FindAllFiles and TFileSearcher will not retrieve filenames if the target directory contains a semicolon ";" in the name
DescriptionThe free pascal function "FindAllFiles()" and the class "TFileSearcher" are BUGGY in very unusual cases.
If a Directory name contains a semi-column ";" in the name (for example directory "abcde;efgh" then no file names will be retrieved
from that directory! This is because Lazarus/free pascal somewhere reserves the ';' semicolumn as a separator for the mask of filenames to retrieve.
For example '*.pas;*.inc;*.pdf' . Had free pascal used for example the pipe char '|' as a separator (a character that is not allowed by a OS in file or
directory names) this bug would not occur. But a semi-column is allowed in file and directory names thus the separator is interfering!
When using the class TFileSearcher, there is a property "MaskSeparator" that can be set, but setting it to '|' does not aliviate this bug,
as the contents of a directory containing a semi-column in the name still will not be retrieved.
I had to create my own substitute class for "TFileSearcher" (using FindFirst() and FindNext() in order to be able to retrieve the contents of directories containing a semi-column ';' in the directory name.
Steps To ReproduceJust create a directory with a name like "c:\myspecial;Directory" containing more than one file inside and try to retrieve the names of those files using "FindAllFiles()" or "TFileSearcher". You will obtain a TStringList object without any file names in it.
TagsNo tags attached.
Fixed in Revision59687
Attached Files


Bart Broersma

2018-11-26 12:59

developer   ~0112204

Last edited: 2018-11-26 13:06

View 2 revisions

Please move to Lazarus. FindAllFiles is part of Lazutils package.

The separator for directories to search is hardcoded as ';' in TFileSearcher.Search.

Juha Manninen

2018-11-26 14:37

developer   ~0112208

Last edited: 2018-11-26 14:38

View 2 revisions

Miguel, maybe you mean semicolon instead of semi-column.
Using it as part of a directory name sounds like begging for trouble.

Bart Broersma

2018-11-26 21:10

developer   ~0112217

Last edited: 2018-11-26 21:11

View 2 revisions

Yes, but it's not illegal.
You cannot create it form commandline though:
md a;b will create direcotries a and b
You can in Explorer however.

We should make the separator a property of TFileSearcher and expose this in FindAllFiles via a default property in one of the overloads.

@Juha: if you object to this idea then please let me know, otherwise I'll implement it when I have the time.


2018-11-26 21:34

developer   ~0112218

There is already a TFileSearcher.MaskSeparator. Can't it be reused for this purpose?

And as a side-note: Recently I noticed that TListDirectorySearcher and TListFileSearcher override the methods DoDirectoryFound and DoFileFound without calling "inherited". Therefore, the events OnDirectoryFound and OnFileFound are never called. Having these events as optional parameters in FindAllDirectories/FindAllFiles might be useful sometimes (e.g. in order to count the total size of all found files - this was a forum question).

Bart Broersma

2018-11-26 21:55

developer   ~0112219

> Can't it be reused for this purpose?
Well, at some point somebody will want a ':' as part of a mask and have it used as pathseparator...

Juha Manninen

2018-11-27 16:32

developer   ~0112234

> @Juha: if you object to this idea then please let me know,

No objections.

Bart Broersma

2018-11-28 17:28

developer   ~0112247

Fixed in r59687.
Please test and close if OK.

@wp: regarding your sidenote in note 0112218: can you open a separate report or commit the changes yourself?
It's rather odd it does not call inherited, so maybe it's on purpose?

Should this be merged to fixes 2?
It changes the signature of FindAllFiles/FindAllDirectories.

Bart Broersma

2018-11-28 17:54

developer   ~0112249

Fixed semi-column->semicolon in summary.

Miguel Oliveira

2018-11-29 15:29

reporter   ~0112261

Hello Juha,
You are right: I meant semicolon, not semi-column! Sorry.
The ';' is being generated automatically when a filename encryption method encrypts a filename or a directory name. The rules for chars to be allowed in filenames exclude several chars like <>:/\| etc, but ';' is not excluded.
I am not creating directories manually and I am not using command line.

Bart Broersma

2018-11-29 19:01

developer   ~0112265

@Miguel: did you try the fix? Does it work. If so please close this issue.

Miguel Oliveira

2018-12-01 12:04

reporter   ~0112290

Hoi Bart,
I did not try the fix because I had already developed an alternative class using FindFirst/FindNext having a better interface for me, because the request method returns a 2-dimensional array containing both directories and files and for each item not not only file name but also file size, filedate and other atributes. I will not be using FindAllFiles any soon.
Anyway I have reported the bug not for myself but for the sake of Lazarus/Free Pascal. I see that the status is already "closed".
Keep up the good work.

Bart Broersma

2018-12-01 16:32

developer   ~0112301

Current staus is no "closed" but "resolved", which means that the person to whom this report is assigned (me) thinks he has fixed the issue.
It is customary for the person who opened the bugreport to close the report (there is a close button beneath the bug description), signaling to the the developer (me) that the fix works for you.

This is common practice in the use of the bugtracker.

Issue History

Date Modified Username Field Change
2018-11-26 12:39 Miguel Oliveira New Issue
2018-11-26 12:59 Bart Broersma Note Added: 0112204
2018-11-26 13:06 Bart Broersma Note Edited: 0112204 View Revisions
2018-11-26 13:19 Michael Van Canneyt Project FPC => Lazarus
2018-11-26 14:37 Juha Manninen Note Added: 0112208
2018-11-26 14:38 Juha Manninen Note Edited: 0112208 View Revisions
2018-11-26 21:10 Bart Broersma Note Added: 0112217
2018-11-26 21:10 Bart Broersma Assigned To => Bart Broersma
2018-11-26 21:10 Bart Broersma Status new => assigned
2018-11-26 21:11 Bart Broersma Note Edited: 0112217 View Revisions
2018-11-26 21:34 wp Note Added: 0112218
2018-11-26 21:55 Bart Broersma Note Added: 0112219
2018-11-27 16:32 Juha Manninen Note Added: 0112234
2018-11-28 17:28 Bart Broersma Fixed in Revision => 59687
2018-11-28 17:28 Bart Broersma LazTarget => 2.2
2018-11-28 17:28 Bart Broersma Note Added: 0112247
2018-11-28 17:28 Bart Broersma Status assigned => resolved
2018-11-28 17:28 Bart Broersma Fixed in Version => 2.2
2018-11-28 17:28 Bart Broersma Resolution open => fixed
2018-11-28 17:28 Bart Broersma Target Version => 2.2
2018-11-28 17:54 Bart Broersma Note Added: 0112249
2018-11-28 17:54 Bart Broersma Product Version 3.0.4 =>
2018-11-28 17:54 Bart Broersma Summary FindAllFiles and TFileSearcher will not retrieve filenames if the target directory contains a semi-column ";" in the name => FindAllFiles and TFileSearcher will not retrieve filenames if the target directory contains a semicolon ";" in the name
2018-11-29 15:29 Miguel Oliveira Note Added: 0112261
2018-11-29 19:01 Bart Broersma Note Added: 0112265
2018-12-01 12:04 Miguel Oliveira Note Added: 0112290
2018-12-01 16:32 Bart Broersma Note Added: 0112301
2018-12-02 11:01 Miguel Oliveira Status resolved => closed