implement list dir

This commit is contained in:
Shota Shimazu 2018-10-26 15:00:12 +09:00
parent 5163872e91
commit 55c6938da4
3 changed files with 28 additions and 2 deletions

View File

@ -26,6 +26,22 @@ extension Fileable {
let path = NSHomeDirectory()
return path
}
/// List contents of specific directory
/// - returns: path array
public var ls: [String]? {
var path: [String]? = []
do {
try path = Fileable.fm.contentsOfDirectory(atPath: self.path)
} catch {
path = nil
}
return path
}
}

View File

@ -36,10 +36,10 @@ extension Fileable {
print("This function is not implemented now.")
}
public static func touch(_ path: String) throws {
public static func touch(at: String) throws {
let empty = ""
do {
try empty.write(toFile: path, atomically: true, encoding: String.Encoding.utf8)
try empty.write(to: URL(string: at)!, atomically: true, encoding: String.Encoding.utf8)
} catch let error as NSError {
print("failed to write: \(error)")
}

View File

@ -36,6 +36,16 @@ class Info: XCTestCase {
XCTAssertFalse(Fileable(file).isFile)
}
func testCaseLS() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
let file: String = Fileable.home
let fileList = Fileable(file).ls!
NSLog(String(describing: fileList))
}
func testPerformanceExample() {
// This is an example of a performance test case.