https://github.com/kylef/pathkit
Effortless path operations in Swift
https://github.com/kylef/pathkit
Last synced: about 1 year 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 (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T18:30:21.000Z (about 2 years ago)
- Last Synced: 2025-04-06T16:09:39.613Z (about 1 year ago)
- Language: Swift
- Size: 207 KB
- Stars: 1,492
- Watchers: 30
- Forks: 172
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
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).