Add shortcut to NSFileManager.defaultManager.

This commit is contained in:
Kare Morstol
2014-12-08 00:05:17 +01:00
parent 8d28ff776d
commit d2c33d562d
2 changed files with 7 additions and 7 deletions
+2 -3
View File
@@ -89,9 +89,8 @@ If the file already exists and overwrite=false, the writing will begin at the en
public func open (forWriting path: String, overwrite: Bool = false) -> WriteableStreamType {
let url = toURLOrError(path)
let filemanager = NSFileManager.defaultManager()
if overwrite || !filemanager.fileExistsAtPath(url.path!) {
filemanager.createFileAtPath(url.path!, contents: nil, attributes: nil)
if overwrite || !File.fileExistsAtPath(url.path!) {
File.createFileAtPath(url.path!, contents: nil, attributes: nil)
}
var error: NSError?
+5 -4
View File
@@ -17,6 +17,8 @@ func toURLOrError (path: String) -> NSURL {
}
}
/** The default NSFileManager */
public let File = NSFileManager.defaultManager()
/**
The tempdirectory is unique each time a script is run and is created the first time it is used.
@@ -25,8 +27,7 @@ It lies in the user's temporary directory and will be automatically deleted at s
public let tempdirectory: String = {
var error: NSError?
let tempdirectory = NSTemporaryDirectory() / "SwiftShell-" + NSProcessInfo.processInfo().globallyUniqueString
NSFileManager.defaultManager()
.createDirectoryAtPath(tempdirectory, withIntermediateDirectories:true, attributes: nil, error: &error)
File.createDirectoryAtPath(tempdirectory, withIntermediateDirectories:true, attributes: nil, error: &error)
if let error = error {
printErrorAndExit("could not create new temporary directory '\(tempdirectory)':\n\(error.localizedDescription)")
}
@@ -43,9 +44,9 @@ separate process and changing the directory there will not affect the rest of th
This directory is also used as the base for relative URL's.
*/
public var workdirectory: String {
get { return NSFileManager.defaultManager().currentDirectoryPath }
get { return File.currentDirectoryPath }
set {
if !NSFileManager.defaultManager().changeCurrentDirectoryPath(newValue) {
if !File.changeCurrentDirectoryPath(newValue) {
printErrorAndExit("could not change the working directory to \(newValue)")
}
}