https://github.com/kylef/PathKit
Effortless path operations in Swift
https://github.com/kylef/PathKit
Last synced: 8 months ago
JSON representation
Effortless path operations in Swift
- Host: GitHub
- URL: https://github.com/kylef/PathKit
- Owner: kylef
- License: bsd-2-clause
- Created: 2014-09-10T16:23:51.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T18:30:21.000Z (over 1 year ago)
- Last Synced: 2025-03-16T13:06:06.027Z (8 months ago)
- Language: Swift
- Size: 207 KB
- Stars: 1,490
- Watchers: 30
- Forks: 171
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - PathKit
- awesome-swift-cn - PathKit - Effortless path operations in Swift. (Libs / Data Management)
- fucking-awesome-swift - PathKit - Effortless path operations. (Libs / Files)
- awesome-swift - PathKit - Effortless path operations. (Libs / Files)
- awesome-swift - PathKit - Effortless path operations in Swift ` 📝 a month ago ` (Files [🔝](#readme))
- awesome-swift - PathKit - Effortless path operations. (Libs / Files)
README
# PathKit
[](https://travis-ci.org/kylef/PathKit)
Effortless path operations in Swift.
## Usage
```swift
let path = Path("/usr/bin/swift")
```
#### Joining paths
```swift
let path = Path("/usr/bin") + Path("swift")
```
#### Determine if a path is absolute
```swift
path.isAbsolute
```
#### Determine if a path is relative
```swift
path.isRelative
```
#### Determine if a file or directory exists at the path
```swift
path.exists()
```
#### Determine if a path is a directory
```swift
path.isDirectory()
```
#### Get an absolute path
```swift
let absolutePath = path.absolute()
```
#### Normalize a path
This cleans up any redundant `..` or `.` and double slashes in paths.
```swift
let normalizedPath = path.normalize()
```
#### Deleting a path
```swift
path.delete()
```
#### Moving a path
```swift
path.move(newPath)
```
#### Current working directory
```swift
Path.current
Path.current = "/usr/bin"
```
#### Changing the current working directory
```swift
path.chdir {
// Path.current would be set to path during execution of this closure
}
```
#### Children paths
```swift
path.children()
```
#### Reading
```swift
path.read()
```
#### Writing
```swift
path.write("Hello World!")
```
#### Glob
```swift
let paths = Path.glob("*.swift")
```
### Contact
Kyle Fuller
- https://fuller.li
- https://twitter.com/kylefuller
### License
PathKit is licensed under the [BSD License](LICENSE).