{"id":32149294,"url":"https://github.com/pelagornis/swift-file","last_synced_at":"2025-12-11T23:00:44.067Z","repository":{"id":140024666,"uuid":"592650299","full_name":"pelagornis/swift-file","owner":"pelagornis","description":"File Management Library with Swift","archived":false,"fork":false,"pushed_at":"2025-10-02T14:18:30.000Z","size":90,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-21T09:53:13.520Z","etag":null,"topics":["file","folder","pelagornis","swift","swift-package-manager"],"latest_commit_sha":null,"homepage":"","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/pelagornis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-01-24T08:06:58.000Z","updated_at":"2025-10-02T14:17:59.000Z","dependencies_parsed_at":"2024-04-14T10:23:53.667Z","dependency_job_id":"88592bcd-77fe-482a-9baa-9789e31bb9b9","html_url":"https://github.com/pelagornis/swift-file","commit_stats":null,"previous_names":["pelagornis/swift-file","pelagornis/plfile"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/pelagornis/swift-file","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelagornis%2Fswift-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelagornis%2Fswift-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelagornis%2Fswift-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelagornis%2Fswift-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pelagornis","download_url":"https://codeload.github.com/pelagornis/swift-file/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pelagornis%2Fswift-file/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280240305,"owners_count":26296527,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["file","folder","pelagornis","swift","swift-package-manager"],"created_at":"2025-10-21T09:53:17.147Z","updated_at":"2025-12-11T23:00:44.049Z","avatar_url":"https://github.com/pelagornis.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# File\n\n![Official](https://badge.pelagornis.com/official.svg)\n![SPM](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)\n![Swift](https://img.shields.io/badge/Swift-6.2-orange.svg)\n[![License](https://img.shields.io/github/license/pelagornis/swift-file)](https://github.com/pelagornis/swift-file/blob/main/LICENSE)\n![Platform](https://img.shields.io/badge/platforms-iOS%2013.0%7C%20tvOS%2013.0%7C%20macOS%2010.15%7C%20watchOS%206.0-red.svg)\n\n📁 **File** is a powerful and intuitive file management library for Swift. It simplifies file and folder operations, providing a consistent API across different platforms. File is designed to make working with the file system a breeze, whether you're reading, writing, creating, or deleting files and folders.\n\n## Installation\n\nFile was deployed as Swift Package Manager. Package to install in a project. Add as a dependent item within the swift manifest.\n\n```swift\nlet package = Package(\n    ...\n    dependencies: [\n        .package(url: \"https://github.com/pelagornis/swift-file\", from: \"1.1.0\")\n    ],\n    ...\n)\n```\n\nThen import the File from thr location you want to use.\n\n```swift\nimport File\n```\n\n## Documentation\n\nThe documentation for releases and `main` are available here:\n\n- [`main`](https://pelagornis.github.io/swift-file/main/documentation/file)\n\n## Using\n\nPath Setting.\n\n```swift\nlet path = Path(\"/Users/ji-hoonahn/Desktop/\") // example\n```\n\nEasy access path.\n\n```swift\nPath.current\nPath.root\nPath.library\nPath.temporary\nPath.home\nPath.documents\n```\n\n#### Writing String Data\n\nThis example demonstrates how to create a file and write a string to it.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"example.txt\")\ntry file.write(\"Hello, File!\")\n```\n\n#### Writing Binary Data\n\nThis example shows how to write binary data to a file.\n\n```swift\nimport Foundation\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"binary.data\")\nlet data = Data([0x00, 0x01, 0x02, 0x03])\ntry file.write(data)\n```\n\n#### Appending String Data\n\nThis example demonstrates how to append a string to an existing file.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"example.txt\")\ntry file.append(\" This is appended content.\")\n```\n\n#### Appending Binary Data\n\nThis example shows how to append binary data to an existing file.\n\n```swift\nimport Foundation\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"binary.data\")\nlet data = Data([0x04, 0x05, 0x06, 0x07])\ntry file.append(data)\n```\n\n#### Reading Data\n\nThis example demonstrates how to read data from a file.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"example.txt\")\ntry file.write(\"Hello, File!\")\nlet readData = try file.read()\nif let readString = String(data: readData, encoding: .utf8) {\n    print(readString) // Output: Hello, File!\n}\n```\n\n#### Opening a File (AppKit)\n\nIf `AppKit` is available, this example shows how to open a file using `AppKit`.\n\n```swift\n#if canImport(AppKit) \u0026\u0026 !targetEnvironment(macCatalyst)\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"example.txt\")\nfile.open()\n#endif\n```\n\n#### Handling FileError\n\nThis example shows how to catch and handle `FileError`.\n\n```swift\nimport File\n\nlet path = Path.root\nlet filePath = Path(\"/path/that/do/not/exist/example.txt\")\n\ndo {\n    let folder = try Folder(path: path)\n    let file = try folder.createFile(at: filePath)\n    try file.write(\"this will fail\")\n} catch let error as FileError {\n    print(\"FileError: \\(error.message)\")\n    if let underlyingError = error.error {\n        print(\"Underlying error: \\(underlyingError)\")\n    }\n} catch {\n    print(\"Unexpected error: \\(error)\")\n}\n```\n\n### Folder Examples\n\n#### Creating Subfolders and Files\n\nThis example demonstrates how to create subfolders and files within a folder.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet subfolder = try folder.createSubfolder(at: \"subfolder\")\nlet newFile = try subfolder.createFile(at: \"newFile.txt\")\ntry newFile.write(\"Content of the new file\")\n```\n\n#### Retrieving Files and Subfolders\n\nThis example shows how to retrieve files and subfolders from a folder.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\n_ = try folder.createSubfolder(at: \"subfolder\")\n_ = try folder.createFile(at: \"example.txt\")\nlet files = folder.files\nlet subfolders = folder.subfolders\nprint(files) // Output: Contains \"example.txt\"\nprint(subfolders) // Output: Contains \"subfolder\"\n```\n\n#### Moving and Copying Contents\n\nThis example shows how to move and copy the contents of a folder to another folder.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet destinationFolder = try Folder(path: Path(path.rawValue + \"destination\"))\n_ = try folder.createFile(at: \"example.txt\")\n_ = try folder.createSubfolder(at: \"subfolder\")\ntry folder.moveContents(to: destinationFolder)\nlet files = destinationFolder.files\nlet subfolders = destinationFolder.subfolders\nprint(files) // Output: Contains \"example.txt\"\nprint(subfolders) // Output: Contains \"subfolder\"\n\nlet copyFolder = try Folder(path: Path(path.rawValue + \"copy\"))\ntry destinationFolder.copy(to: copyFolder)\n\n```\n\n#### Emptying the Folder\n\nThis example shows how to empty a folder (delete all its contents).\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\n_ = try folder.createFile(at: \"example.txt\")\n_ = try folder.createSubfolder(at: \"subfolder\")\ntry folder.empty()\n```\n\n#### Deleting Content\n\nThis example show how to delete subfolders and file\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"example.txt\")\nlet subfolder = try folder.createSubfolder(at: \"subfolder\")\ntry file.delete()\ntry subfolder.delete()\n```\n\n### FileSystem Examples\n\n#### Renaming\n\nThis example demonstrates how to rename a file or a folder.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"oldName.txt\")\ntry file.rename(to: \"newName\")\nprint(file.name) // Output: newName.txt\n```\n\n#### Moving\n\nThis example shows how to move a file or a folder to a new location.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet destinationFolder = try Folder(path: Path(path.rawValue + \"destination\"))\nlet file = try folder.createFile(at: \"example.txt\")\ntry file.move(to: destinationFolder)\n```\n\n#### Copying\n\nThis example shows how to copy a file or a folder to a new location.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet destinationFolder = try Folder(path: Path(path.rawValue + \"destination\"))\nlet file = try folder.createFile(at: \"example.txt\")\ntry file.copy(to: destinationFolder)\n```\n\n#### Deleting\n\nThis example shows how to delete a file or a folder.\n\n```swift\nimport File\n\nlet path = Path.temporary\nlet folder = try Folder(path: path)\nlet file = try folder.createFile(at: \"example.txt\")\ntry file.delete()\n```\n\n### New Features\n\n#### Existence Check\n\nCheck if a file or folder exists:\n\n```swift\nlet file = try folder.createFile(at: \"existTest.txt\")\nif file.exists() {\n    print(\"File exists!\")\n}\nif folder.exists() {\n    print(\"Folder exists!\")\n}\n```\n\n#### List All Files and Folders (Recursive)\n\nGet all files and folders recursively:\n\n```swift\nlet allFiles = folder.allFiles(recursive: true)\nlet allFolders = folder.allFolders(recursive: true)\n```\n\n#### Symbolic Link\n\nCreate and check symbolic links:\n\n```swift\nlet target = try folder.createFile(at: \"target.txt\")\nlet linkPath = folder.store.path.rawValue + \"link.txt\"\nlet linkStore = try Store\u003cFile\u003e(path: Path(linkPath), fileManager: .default)\ntry linkStore.createSymbolicLink(to: target.store.path)\nif linkStore.isSymbolicLink() {\n    print(\"This is a symbolic link!\")\n    print(\"Destination: \\(linkStore.destinationOfSymbolicLink()?.rawValue ?? \"\")\")\n}\n```\n\n#### File/Folder Permissions\n\nGet and set POSIX permissions:\n\n```swift\nlet file = try folder.createFile(at: \"perm.txt\")\nlet originalPerm = file.store.getPermissions()\ntry file.store.setPermissions(0o600)\nlet newPerm = file.store.getPermissions()\nprint(\"New permissions: \\(String(newPerm ?? 0, radix: 8))\")\n```\n\n#### File/Folder Change Watch (macOS/iOS)\n\nWatch for changes to a file or folder:\n\n```swift\n#if os(macOS) || os(iOS)\nlet file = try folder.createFile(at: \"watch.txt\")\nlet source = file.store.watch {\n    print(\"File changed!\")\n}\ntry file.write(\"changed!\")\n// Don't forget to cancel the source when done:\nif let src = source as? DispatchSourceFileSystemObject { src.cancel() }\n#endif\n```\n\n## License\n\n**swift-file** is under MIT license. See the [LICENSE](LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpelagornis%2Fswift-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpelagornis%2Fswift-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpelagornis%2Fswift-file/lists"}