Created
October 25, 2016 15:53
-
-
Save melMass/fb51cf324afdddcc9cba291564394718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UPGRADED TO SWIFT 3 | |
// fn_lister.swift | |
// MTB_Kit | |
// | |
// Created by Mel Massadian on 04/10/16. | |
// Copyright © 2016 Mel Massadian. All rights reserved. | |
// | |
import Cocoa | |
import Foundation | |
import AppKit | |
// Get contents of directory at specified path, returning (filenames, nil) or (nil, error) | |
func lutLister(path: String) -> [(filenames: String,luts:[String])] { | |
// Returns the array containing a tupple per folder with an Array of the folder content. | |
// INITIALIZE | |
var newPath = "" | |
var thosLut:[String] = [] | |
var collection:[(String,[String])]=[("Collections",["LUTS"])] | |
let fm = FileManager.default | |
var isDir: ObjCBool = true | |
do { | |
// Return folder content as Array | |
let items = try fm.contentsOfDirectory(atPath: path) | |
// Loop Lut Folders Cats | |
for item in items { | |
// Check if is Directory | |
if fm.fileExists(atPath: item, isDirectory: &isDir)==false{ | |
// TODO: Find a better way for path concatenation | |
newPath = path+"/"+item | |
// Return LUTs as Array in Category | |
thosLut = try fm.contentsOfDirectory(atPath: newPath) | |
// Append to Collection | |
collection.append((item,thosLut)) | |
} | |
} | |
return collection | |
} catch { | |
print(error) | |
return [(filenames:"Nope",error:["error"]) as! (filenames: String, luts: Array<String>)] | |
} | |
} | |
//let bundleURL = Bundle.main.resourceURL! | |
//let lutURL = URL(string:"luts", relativeTo:bundleURL)! | |
let lut = "/Users/me/LUT_Folders/" | |
var lutFolders = lutLister(path: lut) | |
for (categorie,luts) in lutFolders { | |
print(categorie,luts) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment