github.com/github.com/nsomar/FileUtils

Easy way to work with files, directories and paths in swift on macOS and linux.


License
MIT

Documentation

File

Build Status codecov Platform Language: Swift Carthage

Easy way to work with files in swift on macOS and linux.

Why?

You are developing a cli and you want to:

  • Read/Write files
  • Create/Delete files
  • Get temporary files

Todo:

  • Handle non textual files contents
  • Rename/Move files
  • Dealing with directories
  • Dealing with globs

This library only deals with textual files contents.

Usage

Create a files

SwiftFile(path: path, fileMode: .write)

//OR
SwiftFile.create(path: path)

Delte a file

SwiftFile.delete(string: path)

Read file content

let content = SwiftFile.read(path: path)

// or
let content = String.read(contentsOfFile: path)

Write file content

SwiftFile.write(path: path, string: "ABCDEF")

// or
"AAAAA".write(toFile: path)

Get temporary file and directory

let tmp = SwiftPath.tempFolder

// or
let tmp = SwiftPath.tempFile

// or
let tmp = SwiftPath.tempFileName(name: "abc.txt")

Installation

You can install File using Swift package manager (SPM) and carthage

Swift Package Manager

Add File as dependency in your Package.swift

  import PackageDescription

  let package = Package(name: "YourPackage",
    dependencies: [
      .Package(url: "https://github.com/oarrabi/File.git", majorVersion: 0),
    ]
  )

Carthage

github 'oarrabi/File'

Tests

Tests can be found here.

Run them with

swift test

Contributing

Just send a PR! We don't bite ;)