[Swift]Documentsフォルダ内のファイル一覧出力
Documentsフォルダ内のファイル一覧出力
private func getFileNames(dir:String) -> [String]{ let path = NSHomeDirectory().stringByAppendingPathComponent("Documents/" + dir) var error: NSError? = nil let fileNames:[AnyObject] = NSFileManager.defaultManager().contentsOfDirectoryAtPath(path,error:&error)! var tmp:[String] = [] for fileName:AnyObject in fileNames { tmp.append(fileName as String) } return tmp } private func logFileNames(){ println("----------------- " + __FUNCTION__ + "---------------------") let files:[String] = self.getFileNames("") for n:String in files { println("\(n)") } }