Skip to content

Commit 8c956bc

Browse files
authored
Files 4.0 (#87)
Files 4.0 This change includes a brand new implementation for Files, that keeps most of the public API intact, while modernizing the underlying implementation. Under the hood, Files now uses value types and protocols, rather than class inheritance - which improves the type safety of the API, and streamlines the underlying code. Error handling is also improved to include more underlying info, and the docs have been reworked to be much more thorough. The API has also been fine-tuned and modernized, dropping the `FileSystem` class in favor of more “Swifty” APIs on `Folder`, introducing more options for creating new files and folders, and making it possible to easily change properties on file system sequences. A list of all changes will be posted as part of this version’s release notes.
1 parent 71d1b04 commit 8c956bc

File tree

4 files changed

+1005
-1096
lines changed

4 files changed

+1005
-1096
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ playground.xcworkspace
3737
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
3838
# Packages/
3939
.build/
40+
.swiftpm/
4041

4142
# CocoaPods
4243
#

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
<a href="https://github.com/Carthage/Carthage">
1414
<img src="https://img.shields.io/badge/carthage-compatible-4BC51D.svg?style=flat" alt="Carthage" />
1515
</a>
16-
<a href="https://github.com/JohnSundell/Marathon">
17-
<img src="https://img.shields.io/badge/marathon-compatible-4BC51D.svg?style=flat" alt="Marathon" />
18-
</a>
1916
<a href="https://swift.org/package-manager">
2017
<img src="https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat" alt="Swift Package Manager" />
2118
</a>
@@ -35,27 +32,31 @@ Welcome to **Files**, a compact library that provides a nicer way to handle *fil
3532
## Examples
3633

3734
Iterate over the files contained in a folder:
35+
3836
```swift
3937
for file in try Folder(path: "MyFolder").files {
4038
print(file.name)
4139
}
4240
```
4341

4442
Rename all files contained in a folder:
43+
4544
```swift
4645
try Folder(path: "MyFolder").files.enumerated().forEach { (index, file) in
4746
try file.rename(to: file.nameWithoutExtension + "\(index)")
4847
}
4948
```
5049

5150
Recursively iterate over all folders in a tree:
51+
5252
```swift
53-
Folder.home.makeSubfolderSequence(recursive: true).forEach { folder in
53+
Folder.home.subfolders.recursive.forEach { folder in
5454
print("Name : \(folder.name), parent: \(folder.parent)")
5555
}
5656
```
5757

5858
Create, write and delete files and folders:
59+
5960
```swift
6061
let folder = try Folder(path: "/users/john/folder")
6162
let file = try folder.createFile(named: "file.json")
@@ -65,48 +66,48 @@ try folder.delete()
6566
```
6667

6768
Move all files in a folder to another:
69+
6870
```swift
6971
let originFolder = try Folder(path: "/users/john/folderA")
7072
let targetFolder = try Folder(path: "/users/john/folderB")
7173
try originFolder.files.move(to: targetFolder)
7274
```
7375

7476
Easy access to system folders:
77+
7578
```swift
7679
Folder.current
80+
Folder.root
81+
Folder.library
7782
Folder.temporary
7883
Folder.home
84+
Folder.documents
7985
```
8086

81-
## Usage
82-
83-
Files can be easily used in either a Swift script, command line tool or in an app for iOS, macOS, tvOS or Linux.
84-
85-
### In a script
87+
## Installation
8688

87-
- Install [Marathon](https://github.com/johnsundell/marathon).
88-
- Add Files using `$ marathon add https://github.com/johnsundell/files.git`.
89-
- Run your script using `$ marathon run <path-to-your-script>`.
89+
Files can be easily used in either a Swift script, a command line tool, or in an app for iOS, macOS, tvOS or Linux.
9090

91-
### In a command line tool
91+
### Using the Swift Package Manager (preferred)
9292

93-
- Drag the file `Files.swift` into your command line tool's Xcode project.
93+
To 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).
9494

95-
### In an application
95+
```swift
96+
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0")
97+
```
9698

97-
Either
99+
### Using CocoaPods or Carthage
98100

99-
- Drag the file `Files.swift` into your application's Xcode project.
101+
Please 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.
100102

101-
or
103+
### As a file
102104

103-
- Use CocoaPods, Carthage or the Swift Package manager to include Files as a dependency in your project.
105+
Since 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.
104106

105107
## Backstory
106108

107109
So, 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.
108110

109-
110111
So, 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? :)
111112

112113
## Questions or feedback?

0 commit comments

Comments
 (0)