Skip to content

Naamio/viila

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Viila

Swift Package Manager macOS Linux License: MIT Twitter: @omnijarstudio

Viila is a Swift library that provides a compact and efficient way to handle filesystem tasks in Swift. It’s primarily aimed at Swift scripting and tooling, but can also be embedded in applications that need to access the file system. It's essentially a thin wrapper around the FileManager APIs that Foundation provides.

Features

  • Modern, object-oriented API for accessing, reading and writing files & folders.
  • Unified, simple do, try, catch error handling.
  • Easily construct recursive and flat sequences of files and folders.

Examples

Iterate over the files contained in a folder:

for file in try Folder(path: "MyFolder").files {
    print(file.name)
}

Rename all files contained in a folder:

try Folder(path: "MyFolder").files.enumerated().forEach { (index, file) in
    try file.rename(to: file.nameWithoutExtension + "\(index)")
}

Recursively iterate over all folders in a tree:

Folder.home.makeSubfolderSequence(recursive: true).forEach { folder in
    print("Name : \(folder.name), parent: \(folder.parent)")
}

Create, write and delete files and folders:

let folder = try Folder(path: "/users/tauno/folder")
let file = try folder.createFile(named: "file.json")
try file.write(string: "{\"hello\": \"world\"}")
try file.delete()
try folder.delete()

Move all files in a folder to another:

let originFolder = try Folder(path: "/users/tauno/folderA")
let targetFolder = try Folder(path: "/users/tauno/folderB")
try originFolder.files.move(to: targetFolder)

Easy access to system folders:

Folder.current
Folder.temporary
Folder.home

Usage

Files can be easily used in either a Swift script, command-line tool or in an app for iOS, macOS, tvOS or Linux.

In an application

  • Use Swift Package manager to include Viila as a dependency in your project.

Questions or feedback?

Feel free to open an issue, or find us @omnijarstudio on Twitter.