Skip to content

Commit

Permalink
Add Folder.subfolder(atPath:)
Browse files Browse the repository at this point in the history
This enables easier access to a subfolder located deep within a folder’s
tree, instead of having to retrieve all the intermediate folders.
  • Loading branch information
JohnSundell committed Mar 10, 2017
1 parent 7575260 commit 73f7102
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ public final class Folder: FileSystem.Item, FileSystemIterable {
public func subfolder(named folderName: String) throws -> Folder {
return try Folder(path: path + folderName, using: fileManager)
}

/**
* Return a folder at a given path that is contained in this folder's tree
*
* - parameter folderPath: The subpath of the folder to return. Relative to
* this folder.
*
* - throws: `Folder.PathError.invalid` if the folder couldn't be found
*/
public func subfolder(atPath folderPath: String) throws -> Folder {
return try Folder(path: path + folderPath, using: fileManager)
}

/**
* Create a file in this folder and return it
Expand Down
9 changes: 9 additions & 0 deletions Tests/FilesTests/FilesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ class FilesTests: XCTestCase {
}
}

func testAccessingSubfolderByPath() {
performTest {
let subfolderA = try folder.createSubfolder(named: "A")
let subfolderB = try subfolderA.createSubfolder(named: "B")
let subfolderC = try subfolderB.createSubfolder(named: "C")
try XCTAssertEqual(folder.subfolder(atPath: "A/B/C"), subfolderC)
}
}

func testEmptyingFolder() {
performTest {
try folder.createFile(named: "A")
Expand Down

0 comments on commit 73f7102

Please sign in to comment.