| 1 |
#!/usr/bin/env instantfpc |
| 2 |
|
| 3 |
{ |
| 4 |
Copyright 2020-2022 Michalis Kamburelis. |
| 5 |
|
| 6 |
This file is part of "Castle Game Engine". |
| 7 |
|
| 8 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 9 |
included in this distribution, for details about the copyright. |
| 10 |
|
| 11 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 |
|
| 15 |
---------------------------------------------------------------------------- |
| 16 |
} |
| 17 |
|
| 18 |
{ List all files matching given mask (like * or *.pas) in current directory |
| 19 |
and subdirectories. |
| 20 |
|
| 21 |
To make this work, |
| 22 |
- install FPC, which should include the instantfpc binary |
| 23 |
- install CGE using FpMake/FpPkg following https://castle-engine.io/fpmake |
| 24 |
|
| 25 |
Then run like |
| 26 |
./castle_list_files |
| 27 |
./castle_list_files '../../src/base/*' |
| 28 |
./castle_list_files '../../src/base/*.pas' |
| 29 |
|
| 30 |
Note that above examples quote parameter in apostrophes, so that castle_list_files |
| 31 |
expands the mask, not the shell. You can also let shell expand the mask (it will then |
| 32 |
pass multiple parameters to this application): |
| 33 |
./castle_list_files ../../src/base/* |
| 34 |
./castle_list_files ../../src/base/*.pas |
| 35 |
} |
| 36 |
|
| 37 |
uses SysUtils, |
| 38 |
CastleParameters, CastleFindFiles; |
| 39 |
|
| 40 |
procedure FileCallback(const FileInfo: TFileInfo; Data: Pointer; var StopSearch: boolean); |
| 41 |
begin |
| 42 |
Writeln(FileInfo.URL); |
| 43 |
end; |
| 44 |
|
| 45 |
procedure Find(const PathAndMask: String); |
| 46 |
var |
| 47 |
FilesCount: Cardinal; |
| 48 |
begin |
| 49 |
FilesCount := FindFiles(PathAndMask, false, @FileCallback, nil, [ffRecursive]); |
| 50 |
Writeln(Format('Found %d files matching "%s"', [ |
| 51 |
FilesCount, |
| 52 |
PathAndMask |
| 53 |
])); |
| 54 |
end; |
| 55 |
|
| 56 |
var |
| 57 |
I: Integer; |
| 58 |
begin |
| 59 |
if Parameters.High = 0 then |
| 60 |
Find('*') |
| 61 |
else |
| 62 |
for I := 1 to Parameters.High do |
| 63 |
Find(Parameters[I]); |
| 64 |
end. |