{"id":14966425,"url":"https://github.com/yiisoft/files","last_synced_at":"2025-04-09T09:09:28.398Z","repository":{"id":38629711,"uuid":"197466830","full_name":"yiisoft/files","owner":"yiisoft","description":"Useful methods to manage files and directories","archived":false,"fork":false,"pushed_at":"2024-09-07T15:27:06.000Z","size":198,"stargazers_count":33,"open_issues_count":4,"forks_count":17,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-29T14:36:14.389Z","etag":null,"topics":["directories","directory","file","files","filesystem","hacktoberfest","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2019-07-17T21:39:30.000Z","updated_at":"2024-09-07T15:27:08.000Z","dependencies_parsed_at":"2024-04-11T04:01:36.758Z","dependency_job_id":"38952771-293d-4409-9100-3b560f64199e","html_url":"https://github.com/yiisoft/files","commit_stats":{"total_commits":135,"total_committers":26,"mean_commits":"5.1923076923076925","dds":0.5777777777777777,"last_synced_commit":"a0dcc62d7a996fb58904efd74e68631a8237cfc9"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"yiisoft/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Ffiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/files/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415957,"owners_count":20935388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["directories","directory","file","files","filesystem","hacktoberfest","yii3"],"created_at":"2024-09-24T13:36:22.036Z","updated_at":"2025-04-09T09:09:28.376Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Files\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/files/v)](https://packagist.org/packages/yiisoft/files)\n[![Total Downloads](https://poser.pugx.org/yiisoft/files/downloads)](https://packagist.org/packages/yiisoft/files)\n[![Build status](https://github.com/yiisoft/files/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/files/actions/workflows/build.yml)\n[![Code Coverage](https://codecov.io/gh/yiisoft/files/graph/badge.svg?token=LpKH0C8PYc)](https://codecov.io/gh/yiisoft/files)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Ffiles%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/files/master)\n[![static analysis](https://github.com/yiisoft/files/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/files/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/files/coverage.svg)](https://shepherd.dev/github/yiisoft/files)\n\nThe package provides useful methods to manage files and directories.\n\n## Requirements\n\n- PHP 8.0 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/files\n```\n\n## FileHelper usage\n\nFileHelper provides static methods you can use for various filesystem-related operations.\n\n### Working with directories\n\nEnsure a directory exists:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$directory = '/path/to/dir';\nFileHelper::ensureDirectory($directory);\n```\n\nEnsure a directory exists, and permission specified is set:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$directory = '/path/to/dir';\nFileHelper::ensureDirectory($directory, 0775);\n```\n\nRemove a directory:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$directory = '/path/to/dir';\nFileHelper::removeDirectory($directory);\n```\n\nRemove everything within a directory but not directory itself:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$directory = '/path/to/dir';\nFileHelper::clearDirectory($directory, [\n    'traverseSymlinks' =\u003e false,\n    'filter' =\u003e (new PathMatcher())\n        -\u003eonly('**.png', '**.jpg')\n        -\u003eexcept('**/logo.png'),\n]);\n```\n\nCheck if directory is empty:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$directory = '/path/to/dir';\nFileHelper::isEmptyDirectory($directory);\n```\n\nCopy directory:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$source = '/path/to/source';\n$destination = '/path/to/destination';\nFileHelper::copyDirectory($source, $destination);\n```\n\nAdditional options could be specified as third argument such as `filter` or `copyEmptyDirectories`.\nCheck method phpdoc for a full list of options.\n\nCopy file:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$source = '/path/to/file';\n$destination = '/path/to/destination';\nFileHelper::copyFile($source, $destination);\n```\n\nAdditional options could be specified as third argument such as `beforeCopy` or `afterCopy`.\nCheck method phpdoc for a full list of options.\n\n### Search\n\nSearching for files:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\nuse Yiisoft\\Files\\PathMatcher\\PathMatcher;\n\n$files = FileHelper::findFiles('/path/to/where/to/search', [\n    'filter' =\u003e (new PathMatcher())\n        -\u003eonly('**.png', '**.jpg')\n        -\u003eexcept('**/logo.png'),\n]);\n```\n\nSearching for directories:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\nuse Yiisoft\\Files\\PathMatcher\\PathMatcher;\n\n$directories = FileHelper::findDirectories('/path/to/where/to/search', [\n    'filter' =\u003e (new PathMatcher())-\u003eexcept('**meta'),\n]);\n```\n\n### Path matchers\n\nA `PathMatcherInterface` can be passed by `filter` key in the `options` argument of a method.\nBoth `PathMatcher` and `CompositeMatcher` implement the `PathMatcherInterface`. `CompositeMatcher` allows\nusing a list of `PathMatcherInterface` sequentially.\n\nPattern matching is based on `yiisoft/strings` package [and is described in its readme](https://github.com/yiisoft/strings#wildcardpattern-usage).\n\n### Other\n\nOpen a file. Same as PHP's `fopen()` but throwing exceptions.\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$handler = FileHelper::openFile('/path/to/file', 'rb');\n```\n\nGet last modified time for a directory or file:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$directory = '/path/to/dir';\n$time = FileHelper::lastModifiedTime($directory);\n```\n\nThe method is different from PHP's `filemtime()` because it actually scans a directory and selects the largest\nmodification time from all files.\n\nRemove a file or symlink:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$file = '/path/to/file.txt';\nFileHelper::unlink($file);\n```\n\nNormalize a path:\n\n```php\nuse \\Yiisoft\\Files\\FileHelper;\n\n$path = '/home/samdark/./test/..///dev\\yii/';\necho FileHelper::normalizePath($path);\n// outputs:\n// /home/samdark/dev/yii\n```\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Files is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Ffiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Ffiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Ffiles/lists"}