Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18934 > unrolled thread
| Started by | SupaPlex <old@gamer.s> |
|---|---|
| First post | 2022-05-02 13:32 +0200 |
| Last post | 2022-05-04 18:28 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.php
RecursiveIteratorIterator: exclude file SupaPlex <old@gamer.s> - 2022-05-02 13:32 +0200
Re: RecursiveIteratorIterator: exclude file "J.O. Aho" <user@example.net> - 2022-05-04 18:28 +0200
| From | SupaPlex <old@gamer.s> |
|---|---|
| Date | 2022-05-02 13:32 +0200 |
| Subject | RecursiveIteratorIterator: exclude file |
| Message-ID | <t4ofh2$b0g$1@gioia.aioe.org> |
--- CODE ---
function main($dir, $md5ContainerFilename) {
$elements = iterator_to_array(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir)
)
);
$records = [];
foreach ($elements as $element) {
if (is_dir($element)){
continue;
}
$record = md5($element) . ' ' . $element;
array_push($records, $record);
}
$recordsStr = implode(PHP_EOL, $records);
file_put_contents($md5ContainerFilename, $recordsStr);
}
main(
'.',
'dir/md5-container'
);
--- CODE END ---
$ cat dir/md5-container
b4d1a9a6ea915fbc185205f2d9b61caf ./dir/file
847971a473761ce82235c3f99d6a483b ./dir/file2
76efa814f29375feaf93f6b08982ae4e ./dir/md5-container
516f8127e52fadca9ede40e54a59f04b ./file
0a9990b3c55615b43bd0b0bbbf43dd06 ./file2
As you can see, among the various files, there is also the file
dir/md5-container
This file should be the container, not part of the content.
How can I do to exclude it?
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2022-05-04 18:28 +0200 |
| Message-ID | <jdfnt5Fs70dU1@mid.individual.net> |
| In reply to | #18934 |
On 02/05/2022 13:32, SupaPlex wrote:
> --- CODE ---
> function main($dir, $md5ContainerFilename) {
> $elements = iterator_to_array(
> new RecursiveIteratorIterator(
> new RecursiveDirectoryIterator($dir)
> )
> );
>
> $records = [];
> foreach ($elements as $element) {
> if (is_dir($element)){
> continue;
> } if(str_ends_with($element, 'md5-container') {
continue;
]
>
> $record = md5($element) . ' ' . $element;
>
> array_push($records, $record);
> }
>
> $recordsStr = implode(PHP_EOL, $records);
>
> file_put_contents($md5ContainerFilename, $recordsStr);
> }
>
> main(
> '.',
> 'dir/md5-container'
> );
> --- CODE END ---
>
> $ cat dir/md5-container
> b4d1a9a6ea915fbc185205f2d9b61caf ./dir/file
> 847971a473761ce82235c3f99d6a483b ./dir/file2
> 76efa814f29375feaf93f6b08982ae4e ./dir/md5-container
> 516f8127e52fadca9ede40e54a59f04b ./file
> 0a9990b3c55615b43bd0b0bbbf43dd06 ./file2
>
> As you can see, among the various files, there is also the file
> dir/md5-container
> This file should be the container, not part of the content.
> How can I do to exclude it?
See code above.
--
//Aho
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web