{"id":15293500,"url":"https://github.com/johnsundell/files","last_synced_at":"2025-05-14T22:07:22.546Z","repository":{"id":37617484,"uuid":"79049474","full_name":"JohnSundell/Files","owner":"JohnSundell","description":"A nicer way to handle files \u0026 folders in Swift","archived":false,"fork":false,"pushed_at":"2022-11-04T09:55:43.000Z","size":320,"stargazers_count":2566,"open_issues_count":25,"forks_count":194,"subscribers_count":49,"default_branch":"master","last_synced_at":"2025-05-14T13:12:24.815Z","etag":null,"topics":["files","folders","script","swift","swift-script","xcode"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JohnSundell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-15T18:00:08.000Z","updated_at":"2025-05-11T20:09:23.000Z","dependencies_parsed_at":"2022-07-12T16:33:55.160Z","dependency_job_id":null,"html_url":"https://github.com/JohnSundell/Files","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnSundell%2FFiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnSundell%2FFiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnSundell%2FFiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnSundell%2FFiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JohnSundell","download_url":"https://codeload.github.com/JohnSundell/Files/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235696,"owners_count":22036963,"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":["files","folders","script","swift","swift-script","xcode"],"created_at":"2024-09-30T16:49:47.075Z","updated_at":"2025-05-14T22:07:17.470Z","avatar_url":"https://github.com/JohnSundell.png","language":"Swift","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"logo.png\" width=\"300\" max-width=\"50%\" alt=“Files” /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://dashboard.buddybuild.com/apps/5932f7d9b0c2b000015d6b79/build/latest?branch=master\"\u003e\n        \u003cimg src=\"https://dashboard.buddybuild.com/api/statusImage?appID=5932f7d9b0c2b000015d6b79\u0026branch=master\u0026build=latest\" alt=\"BuddyBuild\" /\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Swift-5.0-orange.svg\" /\u003e\n    \u003ca href=\"https://cocoapods.org/pods/Files\"\u003e\n        \u003cimg src=\"https://img.shields.io/cocoapods/v/Files.svg\" alt=\"CocoaPods\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/carthage-compatible-4BC51D.svg?style=flat\" alt=\"Carthage\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://swift.org/package-manager\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat\" alt=\"Swift Package Manager\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://twitter.com/johnsundell\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/contact-@johnsundell-blue.svg?style=flat\" alt=\"Twitter: @johnsundell\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nWelcome to **Files**, a compact library that provides a nicer way to handle *files* and *folders*  in Swift. It’s primarily aimed at Swift scripting and tooling, but can also be embedded in applications that need to access the file system. It's essentially a thin wrapper around the `FileManager` APIs that `Foundation` provides.\n\n## Features\n\n- [X] Modern, object-oriented API for accessing, reading and writing files \u0026 folders.\n- [X] Unified, simple `do, try, catch` error handling.\n- [X] Easily construct recursive and flat sequences of files and folders.\n\n## Examples\n\nIterate over the files contained in a folder:\n\n```swift\nfor file in try Folder(path: \"MyFolder\").files {\n    print(file.name)\n}\n```\n\nRename all files contained in a folder:\n\n```swift\ntry Folder(path: \"MyFolder\").files.enumerated().forEach { (index, file) in\n    try file.rename(to: file.nameWithoutExtension + \"\\(index)\")\n}\n```\n\nRecursively iterate over all folders in a tree:\n\n```swift\nFolder.home.subfolders.recursive.forEach { folder in\n    print(\"Name : \\(folder.name), parent: \\(folder.parent)\")\n}\n```\n\nCreate, write and delete files and folders:\n\n```swift\nlet folder = try Folder(path: \"/users/john/folder\")\nlet file = try folder.createFile(named: \"file.json\")\ntry file.write(\"{\\\"hello\\\": \\\"world\\\"}\")\ntry file.delete()\ntry folder.delete()\n```\n\nMove all files in a folder to another:\n\n```swift\nlet originFolder = try Folder(path: \"/users/john/folderA\")\nlet targetFolder = try Folder(path: \"/users/john/folderB\")\ntry originFolder.files.move(to: targetFolder)\n```\n\nEasy access to system folders:\n\n```swift\nFolder.current\nFolder.root\nFolder.library\nFolder.temporary\nFolder.home\nFolder.documents\n```\n\n## Installation\n\nFiles can be easily used in either a Swift script, a command line tool, or in an app for iOS, macOS, tvOS or Linux.\n\n### Using the Swift Package Manager (preferred)\n\nTo install Files for use in a Swift Package Manager-powered tool, script or server-side application, add Files as a dependency to your `Package.swift` file. For more information, please see the [Swift Package Manager documentation](https://github.com/apple/swift-package-manager/tree/master/Documentation).\n\n```swift\n.package(url: \"https://github.com/JohnSundell/Files\", from: \"4.0.0\")\n```\n\n### Using CocoaPods or Carthage\n\nPlease refer to [CocoaPods’](https://cocoapods.org) or [Carthage’s](https://github.com/Carthage/Carthage) own documentation for instructions on how to add dependencies using those tools.\n\n### As a file\n\nSince all of Files is implemented within a single file, you can easily use it in any project by simply dragging the file `Files.swift` into your Xcode project.\n\n## Backstory\n\nSo, why was this made? As I've migrated most of my build tools and other scripts from languages like Bash, Ruby and Python to Swift, I've found myself lacking an easy way to deal with the file system. Sure, `FileManager` has a quite nice API, but it can be quite cumbersome to use because of its string-based nature, which makes simple scripts that move or rename files quickly become quite complex.\n\nSo, I made **Files**, to enable me to quickly handle files and folders, in an expressive way. And, since I love open source, I thought - why not package it up and share it with the community? :)\n\n## Questions or feedback?\n\nFeel free to [open an issue](https://github.com/JohnSundell/Files/issues/new), or find me [@johnsundell on Twitter](https://twitter.com/johnsundell).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnsundell%2Ffiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnsundell%2Ffiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnsundell%2Ffiles/lists"}